I want the vectorforce physics to be constant

Currently the speed force being applied moves my vehicle with a new chasiss I’m testing.

However the vehicle speed from the force increases while the force does not. Is there any fix for a solution to my problem?

Issue:
https://gyazo.com/f9ea8b79a77f6fe0bd0aaa26acf87189

Line of code that changes the vectorforce once the client has been given network ownership of the part’s physics:
https://gyazo.com/16db25df969e79ba140c5b35ef032804

Any fix? I have no idea how to work with physics.

Basically I want the vehicle to move at a constant pace and not an increasing pace(unless I script it in otherwise)

2 Likes

Well if the force is constant, acceleration is constant, which means velocity increases.

2 Likes

So how do I make it consistent?

Force = Throttle * Power - Drag * Speed

Where Throttle is the user input and drag and power are constant

What is ThrottlePower and what is DragSpeed

Me forgetting how Kuena formats!

Still confused(Throttle is determing to go forwards or backwards from my user input I’m guessing, Power I guess how fast I want it to, no idea what Drag and Speed are though).

Ok so presumably you have some way of determining the user inputs, the vehicle seats by default have a value called throttle that ranges from 1 for full forward and -1 for full backward.

Multiply this by a constant, called power here, for how much force you want the car to have.

Then you need to take off drag. F = ma, so for the car to reach a constant speed there must be a frictional force.
To keep things simple:
Speed = car.Velocity.magnitude
And drag is another constant, more drag means slower top speed

I attempted to apply what you have given me:
https://gyazo.com/bb4d5a30f0d3797b8eea374d1b51731a

But the vehicle still doesn’t behave like I want it to(not I only want the X coordinate in the VectorForce’s Force to be affected).

Ah sorry, you’re using BodyForce are you? I was assuming BodyThrust.

No, I’m using a vectorforce: http://wiki.roblox.com/index.php?title=API:Class/VectorForce

I could try a bodythrust and see if it produces different results.

Is your ‘relative to’ property set to the car chassis CFrame?

RelativeTo Attachment0
https://gyazo.com/6bb4dad5e2fea26fbce7cd69d77add27

Sorry, my fault for not reading through properly.

Speed = car.Chassis.Velocity.magnitude --approximation
vf.force = Vector3.new(Throttle * Power - Drag * Speed,0,0)

That should do it. You may experience problems if the car has significant speed in the (relative to the car) Y and Z directions, I can fix this if you like.

Edit: I’ll attach it here in case you need it

Speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).x

I used the other one at first because it’s more intuitive, then decided it’s better to use the more reliable one, then I decided I need some sleep as I’m making a mess of this.

3 Likes

Implementation so far:
https://gyazo.com/73db817a57d14553bbe14190afb275e2

The vehicle goes at a constant speed forward, thank you!
https://gyazo.com/0b8c8f3cb9b1fab02d9904580b38645f

But backwards is a different story:
https://gyazo.com/c44b035959b08419a6f6b5dde8c4107c

I tried inversing some variables to fix backwards, but the backwards seems to want to misbehave and continue going.

Sorry, me being dumb again. Lets try this again.

Speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
Dir = math.sign(Speed) --1 when the car is going forwards, -1 for backwards
vf.force = Vector3.new(Throttle * Power - Drag * Speed * Dir,0,0)

When going backwards, the direction of the friction needs to be flipped, and the above code should now do that.

I swear I know how to program cars

2 Likes

https://gyazo.com/ecb4bb2334f297e67a89692d2e30681a

And I’m still going backwards fast.
This updated in a RenderStepped loop btw

Speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)

with this line, Speed will return a Vector3. I assume you want the magnitude of this vector instead, which would be:

Speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).magnitude

I tried that and still the chasis drives backwards without stopping.

Your car is going backwards so fast because the base force (Throttle * Power) is negative and the drag (Drag * Speed) is also negative. This means that when you go backwards, your “drag” force gets higher and increases in acceleration the faster you go. It’s supposed to decelerate you, not accelerate you.

When the car goes forwards, it reaches a speed limit because the base force (Throttle * Power) is positive while the drag (Drag * Speed) is negative. You reach top speed when the two are approximately opposites and add up to 0.

Obviously, if both are negative then they will never add to equal 0. The speed will just increase constantly since the car gets a higher and higher acceleration (force).


@madattak tried to fix this by getting the relative velocity of the car instead of the speed. Speed is directionless – it must be a positive number indicating how fast you are going in any direction. Velocity on the other hand indicates a direction, which is exactly what we need!

What we need is for the drag to be positive – instead of negative – if the car is moving backwards. If we use the X Velocity instead of the Speed, we can get a “negative speed” since velocity includes direction.

This is what @madattak tried to do, but he didn’t get just the X velocity, he tried to use the whole Vector X, Y, and Z velocities at once. This caused an error. I figure this was a typo.

Additionally, multiplying Dir by “Speed” would cause the negatives to cancel out and we’d end up back at step 1.

Here is an amended example script that should work:

AxisVelocity = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).X
vf.Force = Vector3.new(Throttle * Power - Drag * AxisVelocity,0,0)

I tested this out with a power of 10000 and a drag of 100 and was able to reach a top speed of 62 both forwards and backwards.