0 votes

I want to be able to direct my object(rigid body) with "WSAD" keys but when camera follows it always go to spesific direction rather than transforming according to my current position.

I have seen many example with kinetic body but no use for rigid body

const FlOOR_NORMAL := Vector3.UP
func look_follow(state, current_transform, target_position):
    var up_dir = Vector3(0, 1, 0)
    var cur_dir = current_transform.basis.xform(Vector3(0, 0, 1))
    var target_dir = (target_position - current_transform.origin).normalized()
    var rotation_angle = acos(cur_dir.x) - acos(target_dir.x)

    state.set_angular_velocity(up_dir * (rotation_angle / state.get_step()))

func _integrate_forces(state):
    var target_position = $".".get_global_transform().origin
    look_follow(state, get_global_transform(), target_position)

    if Input.is_action_pressed("ui_space"):
        apply_central_impulse(Vector3.UP * 1.5)
    if Input.is_action_pressed("ui_w"):
        apply_impulse(cur_dir, Vector3(2, 0,0))
#       apply_central_impulse(Vector3.FORWARD * 1.5)
    if Input.is_action_pressed("ui_d"):
        apply_central_impulse(Vector3.RIGHT * 1.5)
    if Input.is_action_pressed("ui_a"):
        apply_central_impulse(Vector3.LEFT * 1.5)
in Engine by (193 points)
edited by

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 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.