Progressively changing angular velocity on RigidBody2D

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

Hey guys,
Any idea how can I change progressively angular velocity on RigidBody2D . I am trying to rotate circle. I used on my rigidbody get_node("WheelComponentsRigid").set_angular_velocity(4)
and i tried with Node Timer to do something but it is not smart . :S
Any idea I am stacked up :S

Thank you in advance !

:bust_in_silhouette: Reply From: Zylann

Do you want this to be an animated value, or a “motor” acceleration when the player presses “accelerate”?

For the first case, I would try to animate the angular_velocity property (if there is one?) with an AnimationPlayer.

For the latter, I would do something like this in _process:

if must_accelerate:
	if wheel.get_angular_velocity() < max_velocity:
		wheel.set_angular_velocity(wheel.get_angular_velocity() + acceleration*delta)

max_velocity being an angle/second and acceleration being in spaceUnit/seconds² (spaceUnit being meters or whatever you choose)

:bust_in_silhouette: Reply From: ludosar

you can also add use a tween.

Add a tween to your main node, then add this in the script:

onready var tween = get_node(“tween”)

func _change_velocity():
tween.remove_all()
tween.interpolate_property(get_node(“WheelComponentsRigid”), “velocity/angular”, 0, 4, 1.0, Tween.TRANS_LINEAR, Tween.EASE_OUT, 0)
tween.start()

I can’t get trans_type and easy_type that’s in your code Tween.TRANSLINEAR, Tween.EASE_OUT and I am not sure about property “velocity/angular”. @ludosar

huseng | 2016-08-19 12:37

Underscore characters have been stripped out, here is the formatted code:

onready var tween = get_node("tween")

func change_velocity():
	tween.remove_all()
	tween.interpolate_property(get_node("WheelComponentsRigid"), "velocity/angular", 0, 4, 1.0, Tween.TRANS_LINEAR, Tween.EASE_OUT, 0)
	tween.start()

Zylann | 2016-08-19 12:56