What is the best way of moving single parts?

I’m trying to improve upon the physics of my game, as that is the biggest cause of lag. What I currently use to move the units is a BodyGyro and BodyVelocity inside the main part to aim and move the units in a direction.

I’ve heard that that is inefficient, but I don’t know of a better way as I am inexperienced in roblox physics. Short of coding up my own physics and collision system, is there a better way of moving parts smoothly and predictably?

2 Likes

You could try and use tweenservice and find the distance and divide it by the speed

1 Like

That doesn’t take into account collision. All the units in my game are liable to colliding with each other, and onto parts of the map

1 Like

Every unit could have a PrimaryPart set on its model. (Main part that moves the whole model with it relatively)

You could update every unit by using a stepped event or a loop. For every unit, you calculate the direction it should be moving to and what rotation it should have. Then, set the PrimaryPart’s rotation with a CFrame, followed by a velocity set to speed * direction * deltatime (If it were calculated by frame).

Should be more efficient then having BodyGyro/BodyVelocity all over.

4 Likes

This would be forcing me to develop my own collision system.

1 Like

No, by setting the velocity of a part, it should still respond to the Touched events. Every part has a Velocity property which is simulated and used by the physics. You’re just overriding it with your own values.

However, if it ever does fail, raycast from your previous position to the new one and check if you hit anything along the way.

1 Like

I see what you mean. I’ll have to code that up and compare with BodyGyro+BodyVelocity, thanks

1 Like

No problem, it’s always good to try out both methods. You don’t want to dig too deep and regret it afterwards!

1 Like

Are your physics owners the players or do you keep it on the server for security reasons?

1 Like

It had to be changed to the server for security reasons. It didn’t make a huge difference in lag when I made this change very recently after 3 years however.

1 Like

So your main cause of concern for lag is a single part being moved on the server with BodyGyro and BodyVelocity and it’s causing lag? I just want to better understand the problem.

1 Like

It’s never a single part that causes lag. It’s usually a lot of parts that do it, 150+. And normally it happens when they are colliding a lot with each other, not so much when they are all going in one direction/separated from each other.

1 Like

I think your issue is small parts colliding causing lag, I know for a fact that for gun systems, gun models will drop the game to 10 fps if you walk next to a detailed stone path of around 100 parts. Try testing with bigger parts and see if the issue is as bad.

1 Like

I cannot test with bigger parts as I have just one part per unit and that is its collision box. I’m aware of that problem though, I remember it being common in older games.

1 Like