summaryrefslogtreecommitdiffhomepage
path: root/Racing-Game/4WheelCar/BackWheel.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Racing-Game/4WheelCar/BackWheel.gd')
-rw-r--r--Racing-Game/4WheelCar/BackWheel.gd44
1 files changed, 12 insertions, 32 deletions
diff --git a/Racing-Game/4WheelCar/BackWheel.gd b/Racing-Game/4WheelCar/BackWheel.gd
index b5d8297..9c9adff 100644
--- a/Racing-Game/4WheelCar/BackWheel.gd
+++ b/Racing-Game/4WheelCar/BackWheel.gd
@@ -7,26 +7,18 @@ var isForward = true
var velocity
-var lastLoc = 0;
-
-var wheelSlip = Vector2(0,0);
var isSkid = false;
-signal slip
-signal end
var elapsed = 0
-#
+
var gripDelay = 0
var carAngle
var carVector
var velVector
-# Called when the node enters the scene tree for the first time.
func _ready():
- lastLoc = get_position_in_parent()
- pass # Replace with function body.
+ pass
-# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
carAngle = get_node("../../../CarBody").get_transform().get_rotation()
carVector = Vector2(cos(carAngle + PI/2),sin(carAngle + PI/2))
@@ -34,18 +26,17 @@ func _process(delta):
velocity = measure_velocity()
isForward = is_forward()
set_rotation(carAngle)
- isSlip(delta)
# gripDelay = has_grip(0.4,delta)
isSkid = Input.is_action_pressed("grip")
- if Input.is_action_pressed("grip") || Input.is_action_pressed("break"):
+ if Input.is_action_pressed("grip") || Input.is_action_pressed("brake"):
null_slide(max(5,velocity/7),delta)
else:
null_slide(1,delta)
#Braking
- if Input.is_action_pressed("break"):
+ if Input.is_action_pressed("brake"):
if velocity > 20:
linear_damp = 2
else:
@@ -53,20 +44,19 @@ func _process(delta):
else:
linear_damp = 0.01
-# createLine(lastLoc, get_position_in_parent())
-# lastLoc = get_position_in_parent()
if Input.is_action_pressed("forward"):
- if !Input.is_action_pressed("break"):
+ if !Input.is_action_pressed("brake"):
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("break"):
+ if !Input.is_action_pressed("brake"):
apply_central_impulse(Vector2(0,(1)).rotated(carAngle)*delta*5000)
else:
pass
+#Core physics, stops sliding sideways and make car roll forwards
func null_slide(var strength, var delta):
#strength is how strong you would like the nullify to be
#higher is less sliding/drifting
@@ -74,20 +64,9 @@ func null_slide(var strength, var delta):
var directionAngle = carAngle + (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
+ var wheelSlip = (-(movementUnitVector - nullify))*strength
apply_central_impulse(wheelSlip*delta*5000)
-
-func isSlip(time):
- if (wheelSlip.length() > 0.2):
- emit_signal("slip")
- else:
- emit_signal("end")
-#func createLine(from, to):
-# var tires = get_node("./MyLine")
-# tires.add_point(from)
-# tires.add_point(to)
-
#func has_grip(var tractionDelay, var delta):
# var movementUnitVector = get_linear_velocity().normalized()#the direction of the velocity
# var directionAngle = carAngle#the angle the car is facing(relative to the world)
@@ -107,9 +86,10 @@ func isSlip(time):
func measure_velocity():
return sqrt(get_linear_velocity().dot(get_linear_velocity()))/12
-
-func is_forward():#determines if the car is driving forward, or backward
- var carVector = Vector2(cos(carAngle + PI/2),sin(carAngle + PI/2))
+
+#determines if the car is driving forward, or backward
+func is_forward():
+ carVector = Vector2(cos(carAngle + PI/2),sin(carAngle + PI/2))
if velVector == Vector2(0,0) || carVector == Vector2(0,0):
return true
if velVector.dot(carVector) <= 0: