How do you code a camera that moves WITH the player?
No, I don’t want it attached to the player.
No, I don’t want it to have limits.
No, I can’t have a still camera.
I have a 2D game where the game takes place in a 3D plane (I have an orthogonal camera to make it look 2D) and trying to make the player move with the mouse requires the player to rotate and, therefore, the camera. I can get around the sprite rotation ($Sprite3D.rotation.y = -rotation.y), but the same logic doesn’t work with the camera for some reason.
I litterally just want the camera to move without turning, yet still following the player.
I plan on making it work with the parent node somehow but have no Idea how.
I imagine you’re movement is locked moving probably on Z/Y so you need to follow the player by moving on those axis only.
This is a small script I created to do something like that:
extends Camera3D
@export var target : Node3D
@export var camera_offset : Vector3 = Vector3(0.0, 1.5, 3.0)
@export var look_at_offset : Vector3 = Vector3(0.0, 1.5, 0.0)
@export var camera_follow_speed : float = 10.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var target_position = target.transform.origin + look_at_offset
var camera_position = target.transform.origin + camera_offset
transform.origin = camera_position
look_at_from_position(camera_position, target_position, Vector3.UP)
Just put it on a separate sibling node, save the player/target as an export variable and update camera position to target position plus offset in process or however you feel like. If needed, update offset before use, based on direction player is moving/facing/whatever you want.
You can choose to update only position.x, y or z or any combination of the three depending on what you need.
You can take a look at my Camera3D Plugin which has a number of 3rd person cameras that can do that. You can asee most of them at work in my game Skele-Tom, including a number of cameras that make the 3D game look 2D from multiple angles.
This is a very limiting requirement, and seems quite arbitrary given the rest of your post.
This is not a property of Camera3D nodes. Only Camera2D nodes can have limits, and you cannot use one to do what you want to accomplish.
This is obvious from your request.
My plugin will do this for you.
This is where your post gets really weird. You have all these requirements, as if you have a particular plan, and then you say that you don’t actually know what your architecture looks like. Like your requirement not to be attached to the player, it is a very limiting requirement.
It might help if you described why your camera MUST be attached to a parent node (and what parent node that is). It sounds like you’ve come up with a partial solution to your problem that is frankly, overly complex. Perhaps if you shared a bit more about where all these restrictions came from, and why you have them, it might lead to an answer that was less complicated for you to implement.