alignAxisToVect what is like in GDscript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bishop
:warning: Old Version Published before Godot 3 was released.

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:
		self.rotate_z(0.005)
	if right == false:

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

And another demo (basically for touch controls) which uses that “technique”:
Loading...

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.

wombatstampede | 2017-12-04 15:17