Physics Best Practices

Such content should ideally go on the Developer Hub / API documentation – not great to set the expectation that these things should be found on obscure places on Developer Forum.

Longer posts like this one are good for the Developer Forum.

6 Likes

I agree, there’s lots of valuable information & guides that staff and others have posted on the forum recently, but unless for whatever reason they are replied to often, they just get lost among all the other posts

1 Like

You mention you do interpolation when a client is not the physics owner, but is it just linear interpolation or something more complicated? Is velocity replicated through the network or calculated manually based on change in position/change in time?

I really liked this post, the body movers being deprecated without giving constraint maxforce/torque/velocity/angularvelocity etc vector types is really limiting though, and I can’t ever really use them without the feature requests for vector types being implemented

1 Like

We chose for this post to go on the Forums because we want to rapidly update it with more info and answers to questions over time. The Developer Hub doesn’t lend itself to that very well. We had a lot of great questions and topics come up in the Physics Survey and Discussion post last month, a lot of which is addressed here, and want to continue addressing these kinds of questions as they come up across the forums over time.

This post will absolutely get put on the Developer Hub later, just not right away.

2 Likes

The server simulates assemblies then replicates the position, orientation, linear and angular velocities. The specific method is known as Hermite spline. The post has been updated!

Can you elaborate on what you mean by vector types?
I also want to clarify that we aren’t done adding features to Constraints, just that we won’t be adding features to BodyMovers.

4 Likes

If we want to only AlignPosition on one axis for example we have to update Attachment1’s position every stepped right now (as opposed to if MaxForce were a Vector not a float type, we could just set it to <0,desiredForce,0>)
Would this updating fall under the cframe teleporting?

Also would it be possible to note what changes you make to the post so we dont have to re-read it/store a copy of it and diff it every time?

2 Likes

Would using a Prismatic constraint work? A prismatic forces a part to slide along only one axis.

And I thought about marking edits in the post, but there’s no extra info in the edit than there was in my reply, I can still mark it if it’s helpful though.

2 Likes

PrismaticConstraints wouldn’t work in my use case which I posted a recorded video of in this post because I wanted the character to still move to the sides and not be locked into the axis

1 Like

I would say that if you are going for more general or nuanced movement, its best to use VectorForce, LineForce, and/or Torque rather than updating CFrame on Stepped. Essentially, apply forces in a given direction when a button is held.

2 Likes

I’m trying to work with AlignPosition contraints, but I’m unable to achieve smooth alignment, as the parts become asleep right before they reach their destination (even though they’re still moving):

2019-07-11_12-07-26
(the distance between the attachments before the parts become asleep is ~0.075 studs)


Since that happens, I’m forced to “snap” the parts together early (by enabling RigidityEnabled property), which looks rather unappealing:

2019-07-11_12-15-47

Is there anything that I could do to prevent that from happening (instead of updating parts’ properties back and forth, to jiggle their way into full alignment)?
Could Roblox’s engine be more sensitive to slower movements so it doesn’t mark it as “not moving”, or mark constraint-active parts to be immune to this?

1 Like

Have you tried increasing responsiveness? You can always limit the speed with MaxVelocity if you want to keep it moving slow, but a higher Responsiveness should make sure that the attachments fully align.

I’m using low Responsiveness to give it a “smooth landing” effect. If I were to increase it, the overall movement would be rather linear, and the landing/stop abrubt & unnatural.
(I honestly would make it even lower if it wasn’t clamped to minimum value of 5, to make it even smoother.)

It does seem like you are dealing with an issue where the part is falling asleep earlier than it should. (You can always use the sleep visualization to verify this).
There are a few edge cases we run into where parts either fall asleep when they shouldn’t or don’t wake up when they should. We are continuing to experiment with ways to mitigate them.

For now, you could try and offset the attachments a bit so your part is in the correct position even if the attachments are offset. You can also continue to configure properties to get closer to the behavior you want, like trying to increase responsiveness in the end rather than enabling rigidity so there’s less of a “snap”. Or maybe an extra VectorFroce you enable to give it an extra little push at the end.

1 Like

I’m new to Roblox, and my big problem is that I can’t find a starting point for the current physics system documentation.

I want to apply a constant force vector to a part. Is BodyVelocity the correct class? It’s confusing because it is grouped under Body Movers in the API, and this post says that body movers are deprecated.

Also, I can’t tell which tutorials are using deprecated classes. For example, this tutorial uses legacy classes but has not been marked a deprecated: Documentation - Roblox Creator Hub

It would also help to have a timeline of physics classes, so that when viewing forum posts and YouTube content we can have a rough idea if they might be using legacy classes.

1 Like

To apply a constant force you can use a VectorForce constraint.
As for constant velocity, we have the AngularVelocity constraint, but there is no LinearVelocity constraint yet. For now, you can use BodyVelocity. BodyVelocity is pretty much the only BodyMover you should need to use, otherwise you can use Constraints, here is a good starting point for them.

There is a good bit of outdated documentation, so I get your confusion. Please make specific requests in https://devforum.roblox.com/c/platform-feedback/developer-hub, thanks.

1 Like

If two parts are either anchored or both unanchored and welded to the same assembly, should they collide/create contacts for each other?

I was told this was the case and that they still create contacts and that you need to give them a collision group that doesn’t collide with itself, but this seems incorrect

No they will not collide with each other or create contacts when in the same assembly.
This is also true with some constraints such as HingeConstraints. Even though the two hinged parts will be in separate assemblies, they will not create contacts between them (unless overridden with a touch event I believe)

1 Like

So I have a script where I CFrame a part under the character using Run Service heartbeat locally is there an alternative to this because I see you said CFraming should be reserved for specific teleportation.

Also Is there any tutorials out there on align position and align orientation?

Right, so if this part that has the CFrame set every frame is intended to have physical interactions with things (collisions, etc), then you may have better results by using an AlignPosition/AlignOrientation. The best tutorials would probably just be the intro to constraints and attachments, and the documentation page for AlignPosition, and AlignOrientation.

But if this is purely for visual purposes, and you don’t need any replication (or you are replicating yourself), then there’s nothing wrong with your approach