How to Tween Linear Velocity in Rigidbody2d?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hard

trying it using but object is moving diagonal (down-right)

var tween = get_node(“Tween”)
func _physics_process(_delta):
myPos = self.position
destination = myPos + Vector2(0,0.1)
tween.interpolate_property(self,“linear_velocity”,myPos,destination,1,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT)
tween.start()
pass

:bust_in_silhouette: Reply From: Inces

Linear velocity is a Vector by which RigidBody moves. It describes the change of positions, a vector of difference between position now and position later. Thus it cannot be tweened with a global position vectors, this would give ridicolous results.

You need to rethink what is it You really want to interpolate. Direction of moving object ? Speed ?
The way your code looks it seems like You want to directly tween global_position of the body. This is not advised, collisions won’t be properly reported that way. Instead interpolate speed. Take direction to your target before tweening ( object position minus target position ), tween custom variable speed from 0 to desired number and in process() apply_impulse() using your normalized direction * this speed.

Sorry, it works with
tween.interpolate_property(self,“linear_velocity”,null,Vector2(100,0),1,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT)

hard | 2021-12-17 18:16