diff options
Diffstat (limited to 'Racing-Game/4WheelCar/Wheels')
| -rw-r--r-- | Racing-Game/4WheelCar/Wheels/BackWheel.gd | 11 | ||||
| -rw-r--r-- | Racing-Game/4WheelCar/Wheels/FrontWheel.gd | 28 | ||||
| -rw-r--r-- | Racing-Game/4WheelCar/Wheels/Skid/SkidController.gd | 2 | ||||
| -rw-r--r-- | Racing-Game/4WheelCar/Wheels/Wheel.gd | 5 | ||||
| -rw-r--r-- | Racing-Game/4WheelCar/Wheels/WheelCreation.gd | 2 |
5 files changed, 28 insertions, 20 deletions
diff --git a/Racing-Game/4WheelCar/Wheels/BackWheel.gd b/Racing-Game/4WheelCar/Wheels/BackWheel.gd index 88df113..f9b67aa 100644 --- a/Racing-Game/4WheelCar/Wheels/BackWheel.gd +++ b/Racing-Game/4WheelCar/Wheels/BackWheel.gd @@ -18,19 +18,20 @@ func _process(delta): velocity = measure_velocity() #--- set_rotation(carAngle) + wheelAngle = get_transform().get_rotation() isSkid = Input.is_action_pressed("grip") - + if Input.is_action_pressed("grip") || Input.is_action_pressed("brake"): nullStrength += max(5,velocity/7) else: - nullStrength += 1 - + nullStrength += 5 + #Braking 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) diff --git a/Racing-Game/4WheelCar/Wheels/FrontWheel.gd b/Racing-Game/4WheelCar/Wheels/FrontWheel.gd index 7a05522..cbffbcc 100644 --- a/Racing-Game/4WheelCar/Wheels/FrontWheel.gd +++ b/Racing-Game/4WheelCar/Wheels/FrontWheel.gd @@ -26,25 +26,31 @@ func _process(delta): velAngle = atan2(velVector.y,velVector.x) isForward = is_forward() #--- - set_rotation(carAngle) - + isSkid = Input.is_action_pressed("grip") - + #Determines if drifting if Input.is_action_pressed("grip") || Input.is_action_pressed("brake"): nullStrength += max(5,velocity/7) else: - nullStrength += 1 - + nullStrength += 4 + #Braking setBrake(0) - null_slide(nullStrength,delta) - + #Steering - if Input.is_action_pressed("steer_left"): - apply_central_impulse(steerDamp*Vector2(0,steer_curve(steerSplitA, steerSplitB, steerHeight, steerLimit,steerMinimum)).rotated(steer_angle())*delta*5000) - if Input.is_action_pressed("steer_right"): - apply_central_impulse(steerDamp*Vector2(0,-steer_curve(steerSplitA, steerSplitB, steerHeight, steerLimit,steerMinimum)).rotated(steer_angle())*delta*5000) + #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)) + nullStrength += 0 + if Input.is_action_pressed("steer_right"): + set_rotation(carAngle+deg2rad(45)) + nullStrength += 0 + else: + set_rotation(carAngle) + wheelAngle = get_transform().get_rotation() + null_slide(nullStrength,delta) #returns the angle the car is facing, relative to the direction it is moving func steer_angle(): diff --git a/Racing-Game/4WheelCar/Wheels/Skid/SkidController.gd b/Racing-Game/4WheelCar/Wheels/Skid/SkidController.gd index df1e054..48249a4 100644 --- a/Racing-Game/4WheelCar/Wheels/Skid/SkidController.gd +++ b/Racing-Game/4WheelCar/Wheels/Skid/SkidController.gd @@ -33,4 +33,4 @@ func _process(_delta): skidRecent.skidDraw = false skidSwitch = false pass - + diff --git a/Racing-Game/4WheelCar/Wheels/Wheel.gd b/Racing-Game/4WheelCar/Wheels/Wheel.gd index d25cec5..ab00de6 100644 --- a/Racing-Game/4WheelCar/Wheels/Wheel.gd +++ b/Racing-Game/4WheelCar/Wheels/Wheel.gd @@ -4,7 +4,8 @@ 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 carAngle #The angle the car is facing(relative to world) +var wheelAngle #the angle the wheel 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 @@ -41,7 +42,7 @@ 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 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 diff --git a/Racing-Game/4WheelCar/Wheels/WheelCreation.gd b/Racing-Game/4WheelCar/Wheels/WheelCreation.gd index 06f354e..c656b7c 100644 --- a/Racing-Game/4WheelCar/Wheels/WheelCreation.gd +++ b/Racing-Game/4WheelCar/Wheels/WheelCreation.gd @@ -25,7 +25,7 @@ func createWheel(locX, locY, type): wheeltemp.set_position(Vector2(locX,locY)) add_child(wheeltemp) wheeltemp.initVars(locX,locY) - + # add_child(tempA) elif(type == "back"): var wheeltemp_resource = load("res://4WheelCar/Wheels/BackWheel.tscn") |
