I am making a car game in Godot. The car is a RigidBody2D and I am currently moving the car using apply_impulse() and apply_torque_impulse().
Here's the question:
How do I make it so that car has more sideways friction and less forward/backward friction?
Please answer with a framerate independent solution.
Here's all the current code (Don't worry about the get_input function, it just basically returns an axis of an input multiplied by it's strength (for example, rotation_speed)):
export var acceleration = 13.5
export var rotation_speed = 32.5
export var reverse_ratio = 0.5
onready var input_container = get_parent().get_node("container")
func get_input(name):
if name == "acc":
if input_container.accelerate_button or input_container.brake_button:
return clamp(input_container.input_vector.y acceleration, acceleration -1 reverse_ratio, acceleration)
else:
return Input.get_action_strength("accelerate") acceleration - Input.get_action_strength("brake") acceleration reverse_ratio
if name == "steer":
if input_container.right_button or input_container.left_button:
return input_container.input_vector.x rotation_speed
else:
return (Input.get_action_strength("steer_right") - Input.get_action_strength("steer_left")) rotation_speed
func integrate_forces(state):
apply_impulse(Vector2.ZERO, Vector2(get_input("acc"), 0).rotated(rotation))
if linear_velocity.rotated(-rotation).x < 0:
apply_torque_impulse(get_input("steer") position.distance_to(position + linear_velocity) / 100 -1)
else:
apply_torque_impulse(get_input("steer") * position.distance_to(position + linear_velocity) / 100)