3D Top down camera

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By neo_add

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?


:bust_in_silhouette: Reply From: bellpepper

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.

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.

neo_add | 2020-10-24 21:47

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.

bellpepper | 2020-10-28 05:47

Thanks so much!!!

neo_add | 2020-10-28 17:10