Best way to tween and move a group of anchored parts (preferably without a model)

Does anyone know a good way of tweening a group of anchored parts (preferably) without using models? I want to achieve a unit movement system. Before, I did it with AlignOrientations to keep units straight and VectorForces to move units. Imagine yourself the lag of a live combat with units colliding with eachother and all active physics under the server…

I’m looking for a way for moving this group of parts around, with freedom to rotate parts to do simple animations such as crouching or turning, smoothened out with tweens.

villager.rbxm (5.0 KB)


Thanks for any help, It’ll be greatly appreciated

1 Like

Honestly the probably easiest and simplest way to do this is to group your selection as a Model and to use :PivotTo(). If you really dislike using Models you could pick a sort of primary part in your selection and specify its target position. Then you calculate the position of every other part relative to your previously picked primary part and add that offset to the primary parts target position to get that parts own target position. Then just tween each part to its respective calculated target position.

1 Like

Do you think :PivotTo will eventually lag if there are many units moving, even more than 1k moving models?

There must be about 50 villagers per team, being 400 units in a 8 player match, all moving about 1-5 times a minute, soldiers will be about 150 per team which will probably constantly move.

I’m looking for a tweened approach so I don’t know if such thing will lag.

PivotTo() is laggier than updating the CFrame directly, but the worst is when you move a model where the parts aren’t welded togheter. For the best performance, weld all the parts together, and only keep one of them anchored, this reduces the cost of moving the parts by A LOT. Then you can change the CFrame property of the anchored part (I am not sure if it works on other parts), or Tween the CFrame property of that part. The parts don’t need to be in a group.

You can also make a custom tweening system, to take advantage of BulkMoveTo(). A custom tween system isn’t laggier (or isn’t significantly laggier) than TweenService. Using BulkMoveTo() to update the CFrame property of all the troups can squeeze out a bit more performance

Another thing you should do is animate the troops on the client only, and animate those that are far from the camera at a lower fps, but spread out the work over multiple frames as to not create lag spikes

Updating the position wont work, as stated here

As for animations, you can tween the C0 and C1 properties of the welds (given you used Welds and not WeldConstraints). To save on performance, organize your “model” to require the least amount of welds to update to do your animation

I am not sure if you could use the animation system to do this, Motor6D work similarly to welds so you might be able to use normal animations if you use an AnimationController?

1 Like

Thank you. This is helpful. I will try it out. Another thing is that units need to move in the server too for spatial queries to know nearby units, parts, etc. How could units move in a non costly way in the server but more animated in the client?

You could update their position right before doing the spacial query, or every second or so. However, if you can avoid it, by instead doing magnitude checks or something (if you want to check for shooting, you can make it so the shots are never missed), that would be ideal

1 Like

As a quick side note, if you need to compute more complex movement behaviour of multiple NPCs at the same time you can probably also make use of Parallel Luau to increase performance.

1 Like

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