buzzbuzz20xx Sorry for any confusion, any rotation I put on the camera other than rotating the player itself or rotating it in the player scene does nothing. I have it rotated 90 degrees in the player scene because the car has its forward velocity applied on the X axis but, I want the car to have the orientation shown on the left, meaning the camera need to be rotated 90 degrees. I followed a tutorial for the car physics, and I've tried changing the force to be applied on the Y axis, but I didn't have any luck, so I just went with the camera rotation option. Here all the code from the tutorial along with a link to it if you think changing that would be easier, though when I tried it wasn't as easy as changing some .Xs to .Ys. https://kidscancode.org/godot_recipes/4.x/2d/car_steering/index.html
extends CharacterBody2D
var wheel_base = 70
var steering_angle = 15
var engine_power = 900
var friction = -55
var drag = -0.06
var braking = -450
var max_speed_reverse = 250
var slip_speed = 400
var traction_fast = 2.5
var traction_slow = 10
var acceleration = Vector2.ZERO
var steer_direction
func _physics_process(delta):
acceleration = Vector2.ZERO
get_input()
apply_friction(delta)
calculate_steering(delta)
velocity += acceleration * delta
move_and_slide()
func apply_friction(delta):
if acceleration == Vector2.ZERO and velocity.length() < 50:
velocity = Vector2.ZERO
var friction_force = velocity * friction * delta
var drag_force = velocity * velocity.length() * drag * delta
acceleration += drag_force + friction_force
func get_input():
var turn = Input.get_axis("steer_left", "steer_right")
steer_direction = turn * deg_to_rad(steering_angle)
if Input.is_action_pressed("accelerate"):
acceleration = transform.x * engine_power
if Input.is_action_pressed("brake"):
acceleration = transform.x * braking
func calculate_steering(delta):
var rear_wheel = position - transform.x * wheel_base / 2.0
var front_wheel = position + transform.x * wheel_base / 2.0
rear_wheel += velocity * delta
front_wheel += velocity.rotated(steer_direction) * delta
var new_heading = rear_wheel.direction_to(front_wheel)
var traction = traction_slow
if velocity.length() > slip_speed:
traction = traction_fast
var d = new_heading.dot(velocity.normalized())
if d > 0:
velocity = lerp(velocity, new_heading * velocity.length(), traction * delta)
if d < 0:
velocity = -new_heading * min(velocity.length(), max_speed_reverse)
rotation = new_heading.angle()