This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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
Godot version 3.4.3
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.