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.

  • buzzbuzz20xx replied to this.
  • turtleguy955 Yes. In your existing script you need to set the camera path to be that dummy node's path:

    @onready var players = {
    	"1" : {
    		viewport = $HBoxContainer/SubViewportContainer/SubViewport,
    		camera = $HBoxContainer/SubViewportContainer/SubViewport/Node2D,
    		player = $HBoxContainer/SubViewportContainer/SubViewport/Map/CharacterBody2D
    	},
    	"2" : {
    		viewport = $HBoxContainer/SubViewportContainer2/SubViewport,
    		camera = $HBoxContainer/SubViewportContainer2/SubViewport/Node2D,
    		player = $HBoxContainer/SubViewportContainer/SubViewport/Map/CharacterBody2D2
    	}
    }

    Once you get it working, change the name to something more appropriate like camera_rig

    turtleguy955 changed the title to 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()
      • xyz replied to this.

        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

          • xyz replied to this.

            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.

              • xyz replied to this.

                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.