0 votes

how write in GDscript this for RigidBody node

self.alignAxisToVect( [0, 0, 1] , 2, 0.05 )

I need for rotate right...left...up...down and when key pressed is false then RigidBody
slowly returns to the horizontal position (default position)

I have this, yet

func _input(event):
    if event.is_action_pressed("right"):
        right = true
    if event.is_action_pressed("left"):
        left = true
    if event.is_action_pressed("up"):
        up = true
    if event.is_action_pressed("down"):
        down = true
func _fixed_process(delta):
    var pos = ship.get_global_transform().basis
    impulse_vector = Vector3(0, 0, -0.15)
    ship.apply_impulse(get_global_transform().origin, impulse_vector)
    if right == true:
    if right == false:
in Engine by (450 points)
edited by

When using physics (i.e. via RigidBody) you can apply a force to an object to let it turn.

In this demo project, I apply forces to 2 opposite positions on a RigidBody to let it turn: (see red arrows)

And another demo (basically for touch controls) which uses that "technique":

Both bodies turn only around the y-axis but this should be extendable to the i.e. x-axis (or relative to the objects current rotation).

Perhaps a start for you. (I hope)

Both projects are for Godot 2.1.4. I assume you're programming for the stable version as you didn't say something else.

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.