diff options
| author | realtradam <[email protected]> | 2020-03-19 03:32:54 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2020-03-19 03:32:54 -0400 |
| commit | c7e8f17ba13d4c9e54764286367a26f25b049dc4 (patch) | |
| tree | 6ed85dcd09186f9884b77d56c81f94136154577a /Racing-Game/4WheelCar/Wheels/Wheel.gd | |
| parent | 57c5f73d0d957dc426d922d591fa5a0dd1452892 (diff) | |
| download | optimal-direction-c7e8f17ba13d4c9e54764286367a26f25b049dc4.tar.gz optimal-direction-c7e8f17ba13d4c9e54764286367a26f25b049dc4.zip | |
fixed up file structure
Diffstat (limited to 'Racing-Game/4WheelCar/Wheels/Wheel.gd')
| -rw-r--r-- | Racing-Game/4WheelCar/Wheels/Wheel.gd | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Racing-Game/4WheelCar/Wheels/Wheel.gd b/Racing-Game/4WheelCar/Wheels/Wheel.gd new file mode 100644 index 0000000..49024fb --- /dev/null +++ b/Racing-Game/4WheelCar/Wheels/Wheel.gd @@ -0,0 +1,63 @@ +extends RigidBody2D + +var velocity #How fast car is moving +var velVector #What direction the car is moving +var velUnitVector #Direction vector, but in a single unit(no magnitude) +var velAngle #The angle of the velocity(relative to world) +var carAngle #The angle to car is facing(relative to world) +var nullStrength #sums up all sources of null to here +var isSkid = false #this one is used when user presses shift. Initially called in this function + +#Skidmarks on floor + +#var gripDelay = 0 + +var wheelSlip = Vector2(0,0) + +var isForward = true + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta): + pass + +func initVars(dataArray): +# #---Creating and attaching pinjoint to wheel + var tempA = PinJoint2D.new() + tempA.set_position(Vector2(dataArray[0],dataArray[1])) + tempA.set_node_a(get_path()) + tempA.set_node_b(get_parent().get_parent().get_path()) + tempA.softness = 0 + tempA.bias = 0 + tempA.disable_collision = true + get_parent().add_child(tempA) +# #--- + pass + +func null_slide(var strength, var delta): + #strength is how strong you would like the nullify to be + #higher is less sliding/drifting + var movementUnitVector = get_linear_velocity().normalized()#the direction of the velocity + 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 + apply_central_impulse(wheelSlip*delta*5000) + +#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 + else: + linear_damp = 6 + else: + linear_damp = 0.01 + + +func measure_velocity(): + return floor(sqrt(get_linear_velocity().dot(get_linear_velocity()))/12) |
