What I mean by this is that the object starts to move fast towards the new position value but as it gets closer to it it becomes less fast and then finally stops at the new position. I hope you get it as I have no idea how else to describe it
How to smoothly change the position of an object?
You could use a Tween.
https://docs.godotengine.org/en/3.5/classes/class_tween.html?#tween
- Edited
Hello,
You can have a look at linear interpolation ("lerp" function).
Something like this could do the trick:
extends Node3D
@export var target : Node3D
func _process(delta):
var a = self.global_position
var b = self.target.global_position
var t = delta * 1.0
self.global_position = lerp(a, b, t)
Note that linear interpolation is used to create points between 2 points (A and B for example).
You start from A and use a parameter (t) that vary between 0 and 1.
So at t=0 you are at A, at t=1 you are on B, at t=0.5 you are between A and B.
In this code we use delta as t value. So you may need to snap the object to the target position when you are close enough, as you will never reach the B value in theory.
(Ex : At 60 fps, delta = 0.0166...)
Hope it helps !
Thanks guys, I'll try it :)