Exactly what it says on the tin.
I have a first-person player with a kinematic body. I want to make it so that it will move forward in the direction that the player faces. I'm working in 3D.
This get what I want when I use translate()
(script attached to player):
func _physics_process (delta):
velocity = Vector3 (0, 0, -1)
velocity = velocity.rotated(Vector3(0,1,0), rotation.y)
translate (velocity * speed * delta)
but not with move_and_slide()
func _physics_process (delta):
velocity = Vector3 (0, 0, -1)
velocity = velocity.rotated(Vector3(0,1,0), rotation.y)
move_and_slide (velocity * speed * delta)
When I use move_and_slide
, it moves in the wrong direction except if the player is oriented at 0 degrees. I know I'm not rotating the relative direction wrong since it works perfectly with translate()
. What's exactly going on here?
This is how the first person/FPS movement is handeled BTW:
func _input (event):
if event is InputEventMouseMotion:
camera.rotation.y -= event.relative.x * sensitivity
camera.rotation.x -= event.relative.y * sensitivity
camera.rotation.x = max (min (camera.rotation.x, PI/2),-PI/2)
rotation.y -= event.relative.x * sensitivity # rotate player