How to fling objects, almost like animating objects via code


Shown in the video (Pet Simulator X) you can see coins flying out a the big stack of coins and then attract straight to the player.

Although I wonder how I can go about creating more complex animations like these using code. I assume you use tween service or body forces, although I’m not too sure how. I would also like to know how the coin attracts to the player.

Here is my current object I want to “animate”
image
image

2 Likes

Can’t use TweenService, it’s not flexible enough. The problem happens if the character moves during the animation, then the end point is different and there’s no good way to deal with that using TweenService. It’s a pretty poor tweening API to be honest.

Anyway, you can write your own tweening library or use physics constraints (body movers are “deprecated” but still available). If you use physics then that takes care of replicating between server and clients so it’s a bit easier. If you don’t, you get a lot more control but that means you also have to do a lot of things yourself, like replicating the effect to the server and all clients (unless you only show the effect for the relevant player).

So which approach do you prefer?

The above statement is correct, that if the player moves, then the Tween endpoint would not be updated, in which case you would need to use Lerp to achieve the same goal.

What I cant tell from the video is whether these are actual physical parts moving, or whether it is simply UI elements in PlayerGui being moved which might be simpler and is the method I use.

Hey Emma, Thanks for the advice.

I ended up using BodyMovers and overall it works pretty good for now. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.