Hard
Hard

Reputation: 21

How to tween Linear Velocity in rigidbody2d godot

trying this code but it moves object diagonally(down-right)

func _ready():
    tween = get_node("Tween")
    pass

func _physics_process(_delta):
    tween.interpolate_property(self,"linear_velocity",null,Vector2(0,0.1),1,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT)
    tween.start()
    pass```

Upvotes: 0

Views: 754

Answers (1)

ydinkov
ydinkov

Reputation: 71

It's hard to figure out what you are trying to accomplish and with which types of Node, however you can try something like this:

var TARGET_VELOCITY = Vector2(0,0.1)
var LERP_SPEED = 1

func _physics_process(_delta):
    var newVelocity = self.linear_velocity.linear_interpolate(TARGET_VELOCITY , delta * LERP_SPEED)
    self.linear_velocity = newVelocity 

From the interpolation tutorial: https://docs.godotengine.org/en/stable/tutorials/math/interpolation.html

Upvotes: 1

Related Questions