Go forward on godot

GODOT 4.4

hi everyone!
I face a very annoying problem with GODOT. I’m doing a 3D project for mobile and the desired configuration was that, if the player pressed on the scene (except objects), he would walk forward in the direction he was (in the horizontal plane).
In my case, the horizontal rotation is marked by Y, and the vertical ones are X and Z; and in the position, the horizontal ones are Z and X, and the vertical one is Y.
In my game, the character starts looking in the direction of -X, her right is -Z and her left is +Z, behind her is X.
My character is composed not of a 3D model, but of a characterbody3d (which I only made so Godot would let me create the character, I don’t use it for absolutely anything), inside it, there is a Colision3d (in the shape of the character which is a vertical parallelepiped), A 3d node as a parent of the 3d camera. The character doesn’t have a model, because I wanted to make her like that.
I created a group containing the collision, the node and the camera, called elisa. One important thing to note is that the camera is the only one that starts with a rotation of -90y.
To make the movement, I made a signal in the root node

func _on_room_1_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) → void:
if event is InputEventScreenTouch:
get_tree().call_group(“elisa”, “mover”)

room_1 is the cenary.

And in the group nodes I put SEVERAL variations of chances to make them move normally, like a character and not go to the fourth dimension .
I tried:

func mover(direction):
translate(direction * 0.1)

func mover():
var direcao = -transform.basis.z
direcao.y = 0
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var direcao = transform.basis.z # Sem o menos
direcao.y = 0
if direcao.length() > 0.001:
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var direcao = transform.basis.z # Troca o - por nada aqui
direcao.y = 0
if direcao.length() > 0.001:
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var direcao = -transform.basis.z
direcao.y = 0
if direcao.length() > 0.001:
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var direcao = transform.basis.z # Tenta com isso pra “frente”
direcao.y = 0
if direcao.length() > 0.001:
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var direcao = transform.basis.x # Direção +X com rotação em Y
direcao.y = 0
if direcao.length() > 0.001:
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var direcao = -transform.basis.z
direcao.y = 0
print(direcao) # Ver a direção calculada
if direcao.length() > 0.001:
direcao = direcao.normalized()
translate(direcao * 0.1)

func mover():
var Direction= rotation.y
if rad_to_deg(Direction) - 90 > -90 and rad_to_deg(Direction) - 90 < 0: position.x += -10.0
if rad_to_deg(Direction) - 90 > -180 and rad_to_deg(Direction) - 90 < -90: position.z += -10.0
if rad_to_deg(Direction) - 90 > -270 and rad_to_deg(Direction) - 90 < -180: position.x += 10.0
if rad_to_deg(Direction) - 90 > -270 and rad_to_deg(Direction) - 90 < 0: position.z += -10.0

func mover():
# Movimento na direção “frente” relativa à rotação em Y
var direcao = Vector3(cos(rotation.y), 0, -sin(rotation.y))
# Move o Node3D pai (e assim todos os filhos como CollisionShape e Camera)
translate(direcao * 0.1)

I tried this all, and nothing worked right

Seems like a lot of repeated code, no real changes between a lot of these transform.basis.z samples.

This one using -transform.basis.z should work nicely, assuming you have the character rotated. Can you explain more about how it fails? What do you expect to happen versus what really happens?

Any chance you can attach a screenshot of your scene tree? This is really hard to follow.

Okayy, thanks for try help, it means a lot! S2

http://youtube.com/post/UgkxLZzR8w2jtlvDFP-jkIhKkHeAo09r96Lf?si=gMOzSel59NW9TTRF
My character called Elisa
http://youtube.com/post/Ugkxq-MNiWef_4GuaddZEJTROJu1d8tzCCtN?si=YSqVxzgrBM_FpsJK
The coordinates

I retested the code you mentioned that should work
When I was facing the -X position, the character did nothing for a while, but then went backwards instead of forwards very quickly.
When I turned to the -z position, the character went very quickly there
And when I turned to the y position, she flew, which she shouldn’t do. She should walk normally
In short..

-X → X
-Z → -Z
Y → Y
-Y → -Y
-X → -X
Z → Z

Y should not have any effect, since it will only move horizontally

The only node in the group that starts rotated is the camera, with -90y, the rest are all 0 in rotation.

If u have any other questions, I’ll be here to answer ^^

You should move the CharacterBody3D instead of each child by group, when the parent moves it takes it’s children with it.

Right now you get double-movement because of this, the “pivot” is a parent of the “player” camera, but I assume both are in the group, so the pivot uses mover and moves, this also moves the camera with it, then the camera uses mover and ends up moving twice.

The other problem with this group set up as opposed to moving the parent is that some of your nodes are rotated different directions, so they will move forwards relative to the direction they face, thus moving in different directions.


Your mover function isn’t tied to any framerate or movement, maybe it would be better to use a variable to keep track of this button press, then move during _physics_process or _process if you really do not need collision on your CharacterBody3D. Without this you may see sporadic movements.

# in the CharacterBody3D, assuming it's the only member of group "elisa"
const SPEED = 2.0
var moving: bool = false

func mover(pressed: bool) -> void:
    moving = pressed

func _process(delta: float) -> void:
    if moving:
        position += -basis.z * SPEED * delta


# in your input control script
func _on_room_1_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
    if event is InputEventScreenTouch:
        # also pass if the event is pressed or released
        get_tree().call_group("elisa", "mover", event.pressed)

http://youtube.com/post/UgkxlUE1_73iNIbLD9waDB_lJSLDXE-Jzygr?si=J1bnR78R8WweOBbw
Character box format

http://youtube.com/post/UgkxTQUQsuSltUj6UQ_uyAYMRaCMXeS_aXaD?si=61gh_LcPyO7W5nz3
The code

It didn’t work, the character made really strange movements when I turned and tried to go forward. I tried to go forward and she went to the left (of her). It was the only movement I could notice, because she moved in such a way that when I turned around, she was thrown far away from the room where she was.

I also put the character as the only member of the Elisa group and only put the code on him, removing the codes from his children.

Another detail is that the character is shaped like a cube, which is already wrong and the character is on the edges of the cube instead of the center, but I don’t care much about that.

you should rotate the CharacterBody3D, not the pivot/player.

You can and it is preferable to paste code to the forum directly

If I rotate the characterbody3d, the character leaves the scene, because it is not in its center and does not have its shape.

Seems like it does have a shape, but you aren’t using physics calculations such as move_and_slide anyways. As for centering that can be altered by moving the children close to the CharacterBody3d’s origin

The problem It happened because the character’s coordinates were starting with -90z and the camera’s coordinates with 90x and -90y. Furthermore, the character’s shape was also bad, but I already fixed it remaking the colission.
Thank you very much for your patience and time.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.