How do I make KinematicBody3d move in the direction it's facing?

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

I’m programming a bullet that can be fired in Godot 4. While it can rotate in the right direction, it doesn’t move in that direction. This is the code that rotates the bullet and makes it move forward.

func _physics_process(delta):
	if PlayerData.StayNearplayer == false:
		$GoBack.start()
		$".".rotation.y = PlayerData.PlayerDirection
		position.z -= MoveSpeed

Is there a way to fix this?

By the way, the Main node for the bullet is a 3d Kinematic Body

Entity2020 studios | 2023-05-28 13:39

You probably want something like position += transform.basis.z * MoveSpeed.

Give a read on this tutorial on the official docs to learn more about transforms.

umaruru | 2023-05-29 20:28