Godot 4
how can i apply velocity where the player is looking. Using characterbody 3d of course. If any more info is needed I can comply
Godot 4
how can i apply velocity where the player is looking. Using characterbody 3d of course. If any more info is needed I can comply
The negative basis.z points in the direction a object is looking. This sample would move forward where ever the body is looking.
velocity = -basis.z * speed
move_and_slide()
thank you
if I wanted to make it where the camera is looking would i say velocity = camera.-basis.z * speed?
The unary negation operator - is always applied left-most -camera.basis.z.
Your camera may have a different transform than the characterbody, if you only rotate the camera then yes use camera.basis, but if you use a parent rotation as part of the camera you might need to use the global transform instead through camera.global_basis. For example most first-person controllers rotate the characterbody around the y axis, and rotate the child camera around the x axis. However most first person controllers only want x-z planar movement, so the camera’s rotation should not be considered, which brings us back to using -basis.z