summaryrefslogtreecommitdiffhomepage
path: root/Racing-Game/4WheelCar
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2020-03-20 02:30:30 -0400
committerrealtradam <[email protected]>2020-03-20 02:30:30 -0400
commit4b85316e457c034c8fab47147b1f0ed4f2bf2c1c (patch)
treeac54003e2cf85cce7dc37ca019c5d72f865636e2 /Racing-Game/4WheelCar
parent727bd8009e3e1392d61f39326cf5a47e69af8cae (diff)
downloadoptimal-direction-4b85316e457c034c8fab47147b1f0ed4f2bf2c1c.tar.gz
optimal-direction-4b85316e457c034c8fab47147b1f0ed4f2bf2c1c.zip
Changed art, and further improved physics
Diffstat (limited to 'Racing-Game/4WheelCar')
-rw-r--r--Racing-Game/4WheelCar/4WheelCar.tscn9
-rw-r--r--Racing-Game/4WheelCar/CarBody.gd13
-rw-r--r--Racing-Game/4WheelCar/CarProperties.gd2
-rw-r--r--Racing-Game/4WheelCar/Weight/Weight.tscn2
-rw-r--r--Racing-Game/4WheelCar/Weight/WeightCreation.gd3
-rw-r--r--Racing-Game/4WheelCar/Wheels/BackWheel.gd12
-rw-r--r--Racing-Game/4WheelCar/Wheels/BackWheel.tscn1
-rw-r--r--Racing-Game/4WheelCar/Wheels/FrontWheel.gd38
-rw-r--r--Racing-Game/4WheelCar/Wheels/FrontWheel.tscn1
-rw-r--r--Racing-Game/4WheelCar/Wheels/Wheel.gd8
-rw-r--r--Racing-Game/4WheelCar/Wheels/WheelCreation.gd12
11 files changed, 68 insertions, 33 deletions
diff --git a/Racing-Game/4WheelCar/4WheelCar.tscn b/Racing-Game/4WheelCar/4WheelCar.tscn
index fd8844f..175e2b7 100644
--- a/Racing-Game/4WheelCar/4WheelCar.tscn
+++ b/Racing-Game/4WheelCar/4WheelCar.tscn
@@ -1,13 +1,13 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://4WheelCar/CarBody.gd" type="Script" id=1]
-[ext_resource path="res://Art(non-orig)/PNG/Cars/big/blue/car_blue_2.png" type="Texture" id=2]
+[ext_resource path="res://Art(orig)/Png/EliseRipoff.png" type="Texture" id=2]
[ext_resource path="res://4WheelCar/Weight/WeightCreation.gd" type="Script" id=4]
[ext_resource path="res://4WheelCar/CarProperties.gd" type="Script" id=6]
[ext_resource path="res://4WheelCar/Wheels/WheelCreation.gd" type="Script" id=9]
-[sub_resource type="RectangleShape2D" id=1]
-extents = Vector2( 35.7301, 58.1399 )
+[sub_resource type="ConvexPolygonShape2D" id=1]
+points = PoolVector2Array( 0, -190, 50, -180, 90, -150, 90, 145, 70, 170, 30, 190, 0, 190, -30, 190, -70, 170, -90, 145, -90, -150, -50, -180 )
[node name="4WheelCar" type="Node"]
script = ExtResource( 6 )
@@ -15,14 +15,13 @@ script = ExtResource( 6 )
[node name="CarBody" type="RigidBody2D" parent="."]
position = Vector2( -0.446396, -0.582428 )
z_index = 1
-mass = 30.0
+mass = 62480.0
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="CarBody"]
texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="CarBody"]
-visible = false
modulate = Color( 0, 0, 0, 1 )
shape = SubResource( 1 )
diff --git a/Racing-Game/4WheelCar/CarBody.gd b/Racing-Game/4WheelCar/CarBody.gd
index 53b73d2..ad14ee4 100644
--- a/Racing-Game/4WheelCar/CarBody.gd
+++ b/Racing-Game/4WheelCar/CarBody.gd
@@ -6,9 +6,10 @@ var speedometerNode
var directionAngle
var directionUnitVector
-
+#curb weight 781kg(body + wheels + engine)
func _ready():
angular_damp = 5
+ mass = 564.8 * 100
pass
@@ -24,9 +25,15 @@ func _process(_delta):
cameraNode.set_position(get_global_transform().get_origin())
speedometerNode.updateSpeed(floor(measure_velocity()))
-#Total speed of the car
+ if(Input.is_action_pressed("brake")):
+ linear_damp = 2
+ else:
+ linear_damp = 0.5
+
+#Total speed of the car(in cm per second)
func measure_velocity():
- return sqrt(get_linear_velocity().dot(get_linear_velocity()))/12
+ #dot product of itself gives the magnitude squared
+ return sqrt(get_linear_velocity().dot(get_linear_velocity()))*0.036
#Gets only the component that is going in the direction of the car
func measure_forward_velocity():
diff --git a/Racing-Game/4WheelCar/CarProperties.gd b/Racing-Game/4WheelCar/CarProperties.gd
index 4374de5..ef6bc23 100644
--- a/Racing-Game/4WheelCar/CarProperties.gd
+++ b/Racing-Game/4WheelCar/CarProperties.gd
@@ -9,6 +9,8 @@ var steerMinimum = 1
var hp = 4.0
var acceleration = 5
+var maxRpm = 0
+
# Called when the node enters the scene tree for the first time.
func _ready():
diff --git a/Racing-Game/4WheelCar/Weight/Weight.tscn b/Racing-Game/4WheelCar/Weight/Weight.tscn
index b3d89ff..a74ecb4 100644
--- a/Racing-Game/4WheelCar/Weight/Weight.tscn
+++ b/Racing-Game/4WheelCar/Weight/Weight.tscn
@@ -8,7 +8,7 @@
[node name="Weight" type="RigidBody2D"]
position = Vector2( -0.446396, 25.4176 )
z_index = 2
-mass = 10.0
+mass = 100.0
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
diff --git a/Racing-Game/4WheelCar/Weight/WeightCreation.gd b/Racing-Game/4WheelCar/Weight/WeightCreation.gd
index a6d9786..a81ec4c 100644
--- a/Racing-Game/4WheelCar/Weight/WeightCreation.gd
+++ b/Racing-Game/4WheelCar/Weight/WeightCreation.gd
@@ -7,7 +7,8 @@ extends Node
# Called when the node enters the scene tree for the first time.
func _ready():
- createWeight(0,30,30)
+ # 156.2 kg
+ createWeight(0,110,15620)
pass # Replace with function body.
diff --git a/Racing-Game/4WheelCar/Wheels/BackWheel.gd b/Racing-Game/4WheelCar/Wheels/BackWheel.gd
index f9b67aa..f2e3e7b 100644
--- a/Racing-Game/4WheelCar/Wheels/BackWheel.gd
+++ b/Racing-Game/4WheelCar/Wheels/BackWheel.gd
@@ -1,7 +1,7 @@
extends "res://4WheelCar/Wheels/Wheel.gd"
#Accelerating
-var hp = 4.0
+var hp = 70000.0
var acceleration = 5
var gripDelay = 0
@@ -31,20 +31,22 @@ func _process(delta):
setBrake(0)
null_slide(nullStrength, delta)
-
+#
if Input.is_action_pressed("forward"):
if !Input.is_action_pressed("brake"):
- apply_central_impulse(Vector2(0,-gear(velocity, hp, acceleration)).rotated(carAngle)*delta*5000)
+ apply_central_impulse(Vector2(0,-50765000).rotated(carAngle)*delta)
+# apply_central_impulse(Vector2(0,-gear(velocity, hp, acceleration)).rotated(carAngle)*delta*5000)
else:
pass
elif Input.is_action_pressed("backward"):
if !Input.is_action_pressed("brake"):
- apply_central_impulse(Vector2(0,(1)).rotated(carAngle)*delta*5000)
+ apply_central_impulse(Vector2(0,50765000).rotated(carAngle)*delta)
+# apply_central_impulse(Vector2(0,(1)).rotated(carAngle)*delta*5000)
else:
pass
func measure_velocity():
- return sqrt(get_linear_velocity().dot(get_linear_velocity()))/12
+ return sqrt(get_linear_velocity().dot(get_linear_velocity()))*0.036
func gear(var rpm, var maxPower, var topSpeed):
diff --git a/Racing-Game/4WheelCar/Wheels/BackWheel.tscn b/Racing-Game/4WheelCar/Wheels/BackWheel.tscn
index c09eaca..6b84664 100644
--- a/Racing-Game/4WheelCar/Wheels/BackWheel.tscn
+++ b/Racing-Game/4WheelCar/Wheels/BackWheel.tscn
@@ -4,7 +4,6 @@
[ext_resource path="res://4WheelCar/Wheels/BackWheel.gd" type="Script" id=2]
[ext_resource path="res://Art(non-orig)/crosshair(isorig).png" type="Texture" id=3]
-
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7.07375, 14.3787 )
diff --git a/Racing-Game/4WheelCar/Wheels/FrontWheel.gd b/Racing-Game/4WheelCar/Wheels/FrontWheel.gd
index cbffbcc..888ad0c 100644
--- a/Racing-Game/4WheelCar/Wheels/FrontWheel.gd
+++ b/Racing-Game/4WheelCar/Wheels/FrontWheel.gd
@@ -4,11 +4,15 @@ extends "res://4WheelCar/Wheels/Wheel.gd"
var steerDamp = 1
#Steering Curve Vars
-var steerSplitA = 20
-var steerSplitB = 40
-var steerHeight = 2.6
-var steerLimit = 73
-var steerMinimum = 1
+#var steerSplitA = 20
+#var steerSplitB = 40
+#var steerHeight = 2.6
+#var steerLimit = 73
+#var steerMinimum = 1
+
+var steerAngle = 0
+var steerStrength = 250 #how fast the wheels turn when holding a direction
+var steerLimit = 60 #how far the wheels will turn up to before stopping
# Called when the node enters the scene tree for the first time.
func _ready():
@@ -42,13 +46,31 @@ func _process(delta):
#if pressing one button, or the other, but not both(xor)
if !(Input.is_action_pressed("steer_left") && Input.is_action_pressed("steer_right")) and (Input.is_action_pressed("steer_left") || Input.is_action_pressed("steer_right")):
if Input.is_action_pressed("steer_left"):
- set_rotation(carAngle-deg2rad(45))
+ if(steerAngle>-steerLimit):
+ steerAngle -= (steerStrength*delta)
+ if steerAngle < -steerLimit:
+ steerAngle = -steerLimit
+ set_rotation(carAngle+deg2rad(steerAngle))#needs to be negative
nullStrength += 0
if Input.is_action_pressed("steer_right"):
- set_rotation(carAngle+deg2rad(45))
+ if(steerAngle<steerLimit):
+ steerAngle += (steerStrength*delta)
+ if steerAngle > steerLimit:
+ steerAngle = steerLimit
+ set_rotation(carAngle+deg2rad(steerAngle))
nullStrength += 0
else:
- set_rotation(carAngle)
+ if(steerAngle < 0):
+ steerAngle += (steerStrength*delta)
+ if(steerAngle > 0):
+ steerAngle = 0
+ elif(steerAngle > 0):
+ steerAngle -= (steerStrength*delta)
+ if(steerAngle < 0):
+ steerAngle = 0
+ set_rotation(carAngle+deg2rad(steerAngle))
+
+
wheelAngle = get_transform().get_rotation()
null_slide(nullStrength,delta)
diff --git a/Racing-Game/4WheelCar/Wheels/FrontWheel.tscn b/Racing-Game/4WheelCar/Wheels/FrontWheel.tscn
index 25644a6..715a3ea 100644
--- a/Racing-Game/4WheelCar/Wheels/FrontWheel.tscn
+++ b/Racing-Game/4WheelCar/Wheels/FrontWheel.tscn
@@ -4,7 +4,6 @@
[ext_resource path="res://4WheelCar/Wheels/FrontWheel.gd" type="Script" id=2]
[ext_resource path="res://Art(non-orig)/crosshair(isorig).png" type="Texture" id=3]
-
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 6.93714, 14.1584 )
diff --git a/Racing-Game/4WheelCar/Wheels/Wheel.gd b/Racing-Game/4WheelCar/Wheels/Wheel.gd
index ab00de6..eacae0b 100644
--- a/Racing-Game/4WheelCar/Wheels/Wheel.gd
+++ b/Racing-Game/4WheelCar/Wheels/Wheel.gd
@@ -45,17 +45,17 @@ func null_slide(var strength, var delta):
var directionAngle = wheelAngle + (PI/2.0)#the angle the car is facing(relative to the world)
var directionUnitVector = Vector2(cos(directionAngle),sin(directionAngle)).normalized()#the direction the car is facing
var nullify = directionUnitVector * movementUnitVector.dot(directionUnitVector)
- wheelSlip = (-(movementUnitVector - nullify))*strength
- apply_central_impulse(wheelSlip*delta*5000)
+ wheelSlip = (-(movementUnitVector - nullify))*500 * 10 * 100
+ apply_central_impulse(wheelSlip*delta*100)
#checks if the car is braking, and applies brake physics
func setBrake(var strength):
#Braking
if Input.is_action_pressed("brake"):
if velocity > 20:
- linear_damp = 3
+ linear_damp = 300000
else:
- linear_damp = 6
+ linear_damp = 600000
else:
linear_damp = 0.01
diff --git a/Racing-Game/4WheelCar/Wheels/WheelCreation.gd b/Racing-Game/4WheelCar/Wheels/WheelCreation.gd
index c656b7c..e7220c3 100644
--- a/Racing-Game/4WheelCar/Wheels/WheelCreation.gd
+++ b/Racing-Game/4WheelCar/Wheels/WheelCreation.gd
@@ -7,10 +7,14 @@ extends Node
# Called when the node enters the scene tree for the first time.
func _ready():
- createWheel(17,-27,"front")
- createWheel(-17,-27,"front")
- createWheel(20,36,"back")
- createWheel(-20,36,"back")
+ var frontSeperation = 73
+ var frontDistance = 115
+ var backSeperation = 75
+ var backDistance = 115
+ createWheel(frontSeperation,-frontDistance,"front")
+ createWheel(-frontSeperation,-frontDistance,"front")
+ createWheel(backSeperation,backDistance,"back")
+ createWheel(-backSeperation,backDistance,"back")
pass # Replace with function body.