im making a little split screen multiplayer game and i having a bit of trouble with camera rotation.
the image above is the viewport. the left side's camera is rotated correctly but the right side's is not. i cant figure out how to make the one on the right to have the same rotation as the one on the left. i think the problem could be stemming from the fact that the CharacterBody2D is rotated -90 degrees in the player scene and camera attached to the player is also rotated 90 degrees in the player scene, but that is because in order to have the car drive straight relative to the camera, it needs to be rotated -90 degrees.
here are the scene setups for the viewport scene and the player scene.
any help would be great and if anything else is needed to help just ask me.
problems with camera orientation
turtleguy955 i think the problem could be stemming from the fact that the CharacterBody2D is rotated -90 degrees in the player scene and camera attached to the player is also rotated 90 degrees in the player scene, but that is because in order to have the car drive straight relative to the camera, it needs to be rotated -90 degrees.
Wait sorry I'm confused, why don't you just go into the Camera node and play around with different rotation degrees and see which one works ?
sorry if I'm misunderstanding the problem, your wording is a bit confusing, maybe i could help if you rephrased it ?
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()
turtleguy955 What's the purpose of the camera in the player scene when you already have a camera in each viewport?
xyz none apparently, but that dosent fix the issue with the orientation in the game scene, now both are fliped like the left one
turtleguy955 Well then rotate both viewport cameras and you're done.
xyz as i stated prior, rotating the viewport cameras does nothing
- Edited
turtleguy955 Have you turned off the ignore_rotation property on those cameras? It's on by default.
xyz yes its disabled on both
turtleguy955 And cameras do not rotate when you adjust their rotation property?
xyz they do not
turtleguy955 Can you post a minimal reproduction project?
xyz yes give me a minute
xyz its done how should i send it to you
turtleguy955 Attach it to a post.
alright here it is
- Edited
turtleguy955 So what exactly is not working here? Everything looks fine. Both cameras rotate in the editor. Your setup creates remote transform nodes that copy each player's transform to corresponding camera's transforms. When you rotate a player, its camera will rotate as well.
xyz The cameras' rotation is offset by 90 degrees in the game window, both icons should have the correct orientation by default. I know It's because the cameras are rotated in the player, but I need them to be so that the driving makes sense in my main project. Changing the code so that the car moves on the Y axis would fix all the problems, but I'm not too sure how to do that.
- Edited
turtleguy955 Well then insert an additional dummy node into hierarchy, parent the camera to it and drive that node with player's transforms. Now the camera is free to be adjusted however you want it. Can even do some tilting/shaking effects.
Don't forget to update the node paths in your setup script so they point to that dummy node instead directly to the cam node.