Body Velocity doesn't work properly

Basically I have been trying to make my own Friction framework that would allow me to control how much an object can slide on a set surface.

I’ve tried using Forces like BodyForce and BodyThrust but as it turns out, if you put then in a Stepped event and the Client that the code runs on has just a bit of lag, the part would start to shake like crazy. Also if you placed it on a slope, as small as 2 degrees, given the friction force of 100.000 newtons, it would still slide.

Thus, I moved on to BodyVelocity, which were very promising at first. The first test I ran was very successful, the friction force that acted on the part was perfectly adjusted by the roblox engine itself, and upon any lag spikes, the part would not shake at all.

As an example, here I’ve set the part on a 20.224 degree slope, and I’ve set the maximum friction acceleration to 50 st/s^2.

1

As how you might have noticed, the part accelerated, without shaking.

Also if you matched the Acceleration of the Friction Force to the Gravitational Acceleration, given a certain slope, the part would no slide unless you pushed it. And it would maintain a constant velocity.

As an example, I’ve calculated the Gravitational Acceleration that acted on the part using the formula g*sin(angle) (that would be equal to about 67.827 st/s^2) and I’ve inserted it into the code.

2

As how you may have noticed, the part stayed still because the sum of the two forces equals 0 newtons. That means no acceleration.

However, If I try to add more than one point that contains the friction force, things start to get messy.

When I split the Friction force into 4 and placed them symmetrically around the part, the sum of the forces, for some odd reason, was smaller than the initial force. I can prove that by running the same test, side by side, of the two systems.

3

As how you may have noticed, the part that had the force split and place symmetrically around it, for some odd reason, accelerated faster than the initial test prototype.

Not only that, but if you pushed the part in such a way that you applied torque to it, it would not stop rotating even if the BodyVelocity.Velocity is set to a Vector3 of (0,0,0)

5%5B1%5D

Here is an Uncopylocked place that you can test the stuff yourself. Maybe look into my code and see if there is anything wrong with it.

Link: Weird BodyVelocity - Roblox

2 Likes

I got the two blocks on the ramp to slide at the same rate by moving this line out of the for loop; however, I’m not really sure about the spinning quite yet.

local totalTime,dt = game:GetService('RunService').Stepped:Wait();
1 Like

I managed to get it to gradually slow down the rotation by adding this outside of the for loop
if mainPart.Velocity == Vector3.new(0, 0, 0) and mainPart.RotVelocity ~= Vector3.new(0, 0, 0) then; mainPart.RotVelocity = Vector3.new(0, 0, 0); end

Hopefully there’s a way to get it to exponentially slow down rather than gradually, because just a light push takes too much time so slow down in my opinion.

1 Like

I played around with it some more and added BodyAngularVelocity to the third model in order to compensate for rotational friction. The code is identical to the implementation of the other body object besides the initialization of the acceleration, which I set on a different axis.

local RotationalAcceleration = Vector3.new(0, Max, 0)

I think this is a good place to start, but I would definitely tweak it to your liking.

1 Like

That is not how it should really work. When that MainPart is rotating, the other four parts that contain the BodyVelocity are moving hence they are not in the center of MainPart. Because they are moving, they must have a certain speed/velocity that needs to be slowed down. I think that it’s more of a Roblox Engine bug than a Coding error.

Yep, that did fix it. Turns out that if you want to work with the Roblox Engine, it’s best to set all of the parameters and only after, do the waiting for the next update.

Thanks!