+2 votes

Hey ! I'm trying to make 3rd person movements like Psychonauts or Ratchet & Clank and my problem is that the rotation of the camera is use to lead the character and I don't understand how I could do that (even in terms of "logic").

My basics movements are based on linear velocity on a RigidBody and support 8 directions movements in the 3D space.

func move_player(speed_x,speed_z, acc, delta):
    current_speed.x = lerp(current_speed.x, speed_x, acc * delta)
    current_speed.z = lerp(current_speed.z, speed_z, acc * delta)
    set_linear_velocity(Vector3(current_speed.x,get_linear_velocity().y, current_speed.z))

func _fixed_process(delta):
    if btn_up:
        move_player(0,-speed, acceleration, delta)
    if btn_down:
        move_player(0,speed, acceleration, delta)
    ## etc...

I think that I should use the forward vector of the camera (var forward = -camera.get_transform().basis.z) but I don't know what to do with it...

in Engine by (31 points)

you can take the camera's forward vector and multiply it to get a forward - backwards movement, and by using the normal vector or the vector's orientation and some trigonometry you can find the vector for horizontal movement. i dont remember the equations too much but you can look up google or try and develop them yourself if you are educated in those subjects

1 Answer

+1 vote

The Kinematic character demo uses that kind of movement

Is a bit rough, though, you may want to add some extra node to keep current direction and do some kind of smooth transition between directions (or not change it until movement stops).

by (7,890 points)
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 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 webmaster@godotengine.org with your username.