0 votes

Hi. So, I'm new at godot/GdScript and i'm struggling to find an answer to my problem.

I'm doing a simple adventure/rpg game and need to set a camera that works like Alundra or Zelda: a Link to the past, but in a 3D environment. Also, I'd like to set orthogonal view.
I've done the character control so, if I set up the camera in the hierarchy tree of him, it keeps rotating along with the character. I need a camera that follows the character but do not rotate with him.
Any ideas?

Thanks

in Projects by (12 points)

1 Answer

0 votes

One solution is to create a spatial node that will serve as a camera base. The camera will be a child of the camera base. The camera base should be a sibling to the player character. Update the position of the camera base to the position of the player using code.

If you wish to forego using a spatial node as a camera base for whatever reason, you can also have the camera be a sibling to the player character. Update the position of the camera to the position of the player with a constant Vector3 offset.

by (77 points)

Thanks, bellpepper.

I get what you said and it makes sense; but I don't know how to make the script you just said. I'm reading the Docs, but I'm not capable of doing it, yet. English is not my birth language so, it's a lot of work, lol.

No worries.

You'll want an onready var <identifier> = get_node(<path>) to refer to the camera in the player's script, or the player in the camera's script.
You'll also want a vector3 variable, for the offset if you're not using a camera base: var offset = Vector3(x, y, z)

You can set the projection view of the camera in the camera's properties by the way, but I mainly use perspective so I'm not sure the compromises you will have to make with orthogonal. I used to achieve a pseudo-orthogonal effect by adjusting the rotation of the camera as I wished to emulate the effect.

If this is in the player's script, you will do:
camera.global_transform.origin = global_transform.origin + offset

If this is in the camera's script, you will do:
global_transform.origin = player.global_transform.origin + offset

EDIT: I just found that in the camera's properties is the "H Offset" and "V Offset" variables, so instead of using code to add an offset, you can use that instead if you so choose.

Thanks so much!!!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories