I’ve currently done it in 2 different ways, and both have worked perfectly
1: I used a While loop to constantly redirect the object to the desired position.
(This while loop runs infinitely until the object reaches the position tolerance.)
2: I used TweenService to make the object go to the exact position.
My question is, what would be better to use, an infinite While loop or TweenService?
Let me explain what I want to do. Let’s say when a player picks up an object, if they take damage or throw it, that object falls to the ground and then returns to its original position.
It’s worth mentioning that the object will be bouncing until it reaches its original position… So what would be the most optimal way to do it?
Both of the options mentioned by the OP are actually the same, because
while task.wait() do
end
is exactly the same as
RunService.Heartbeat:Connect(function()
end)
For the OP, if you want the object to bounce back to its original position, then I don’t think you should refer to the two options, I believe that will require animations of the object to achieve the “bounce” effect.
The thing is, TweenService only cares about tweening the part’s position property to a goal position with any effects applied on, so even if you use TweenService, when the player picks up the part and walks away from the original position, gets hit or drops the object, it wouldn’t do the bounce effect on the ground, instead it’s going to tween the part to the goal position whilst applying the “bounce” effect, because it will take the goal position as the “ground”.
Here’s a video example to explain it better if you don’t get what I mean.
As you can see when I dropped the part, it didn’t bounce on the ground and went back to the position (assume the original position is the origin). It just snapped the handle part back to the position immediately.
So, if you want to make it so that it bounces until it reaches the original position, my best option is probably animations, or, now that I think of it, you can probably create waypoints along the path, and then try to make the bounce effect to play between two adjacent waypoitns until it reaches the last waypoint (end goal) using PathfindingService.
@YoungKnightSoul
That is completely false. Not only that, it is used inappropriately. RunService.RenderStepped should only be used if you are dealing with the player’s camera or the player’s character model.
I was thinking of using a ‘PathfindingService’ for that same purpose, since different maps could utilize it to ensure the object always returns to the center of the map, and then interpolate the bounces from there… So, by using the ‘PathfindingService,’ would you still recommend using animations for the ‘Bounce’ effect?
I was busy over the weekend, but today I was finally able to finish it! Thank you very much I used the PathfindingService and at each Waypoint I altered the height to make the Bounce effect.
It was complicated because I only knew how to use it on humanoids, but then with the Tweenservice I was able to make the desired movement between each Waypoint