Part.Velocity = Part.Velocity is causing my vehicle to act strangely

I was working to improve those Roblox jeeps in some of the starter places, but I kept encountering a weird bug that caused the jeeps to accelerate rapidly in the direction of turning. Some things seemed to make it worse, but eventually I stripped the entire thing down into it’s absolute minimum: Some welded blocks, and this loop:

	while character.Humanoid.SeatPart == car.DriveSeat do
		wait()	
		car.Chassis.RotVelocity = car.Chassis.RotVelocity+Vector3.new(0,movement.X*0.05,0)
	end

Where movement.Y is the Steer input of the vehicle seat. This worked fine, it behaved how you would expect:

However, add one little innocent looking, theoretically harmless line

	while character.Humanoid.SeatPart == car.DriveSeat do
		wait()	
                car.Chassis.Velocity = car.Chassis.Velocity
		car.Chassis.RotVelocity = car.Chassis.RotVelocity+Vector3.new(0,movement.X*0.05,0)
	end

And now we get this:


What!?! Now the car’s suddenly being shoved to the side!
I’ve wasted hours trying to debug code, thinking it was a mistake in my maths and formulas, and hours then tracking down what was causing it on the Roblox side, and I’d greatly appreciate it if anyone could give me an answer to what is happening and if it can be stopped.

The vehicles used are attached here:
BuggedPhysicsJeeps.rbxmx (310.4 KB)

2 Likes

Seems like good ol’ floating point errors to me.
The value that Lua gets is being truncated or slightly changed and then it’s setting that back just for the process to repeat?
Or could be something else entirely.
(Maybe it makes velocity not decrease as fast who knows)

1 Like

I don’t think it’s floating point, it only occurs when both lines are present, setting either RotVelocity or Velocity on its own has no problem.

When the vehicle rotates, that means it is moving, which results in the velocity property changing. I’m not sure why setting it to itself would change it’s behavior, but that could be the problem.

Similar to what @antonio6643 said, rotating the car sets the velocity sideways and has the car rotate. Setting the car’s velocity while trying to have it rotate will have the velocity set sideways, but the car doesn’t rotate since the velocity isn’t properly changing. That’s why one line or the other works, but not both at once, if I’m not mistaken. This is only a theory, so it may or may not be true.

I’m bad at physics, but I’m pretty sure the problem is that as you rotate the car, in order to keep it stationary there needs to be a force to counteract the rotation trying to move it (done by Roblox). Since you constantly set it to the velocity, it essentially counters the force trying to keep it stationary and then you get the movement. You actually get a build up of force that ends up moving it instead while rotating it. Rotation is still motion.

Something I’ve noticed is that the magnitude of the chasis’ velocity increases up until the car makes a complete rotation, then starts to decrease until its 180 degrees from another rotation, then increases.

3 Likes

This shouldn’t be the case. When the object rotates, there should be no overall force acting on it, only a torque. The velocity should be zero either way.

As the vehicle rotates in the “Glitched” model it starts to move towards the direction you rotated in, so that clearly is not the case.