A vehicle chassis with the pacejka friction circle ,raycast suspension, gearbox

Hello! Recently I created a car chassis system that uses ray-cast suspension coupled with the pacejka friction curve, the result is a car that can spin out and have a kinda “believable” physics
it also has a gearbox in which the current gear is determined by the wheel rotation rates.

Would you play a racing game that contained this handling model? If then what type of game should it be? Or would the understeer/oversteer stuff be hard for an average player?

Thanks for your attention :happy3:

here is the place btw

also, feel free to ask questions (no I won’t open-source it)

6 Likes

I feel like robloxs implemented phyiscs would probably be a little better. But if this is a private project and your looking to learn thats no problem. The reason I wouldve chose the already existing physics over custom physics is strictly because its easier to make and you can pretty much fine tune it to feel realistic.

A good saying to keep in mind, dont try to re-invent the wheel, just improve it! Just use already existing modules or systems, and improve on their existing foundation or structure.

On the side note it looks incredibly good👌.

2 Likes

i actualy tried using the roblox implemanted constraints and it felt like i was fighting them instead utilizing them, also i dont realy want an realistic handling i want to for a more sim-cade feel (kinda like blur’s[a silly ps3 game] handling)

Also if you some day going to make a vehicle use raycast stuff its so much easier it might look complicated but its easy if you know basic physics concepts, most complex things are already in the internet just not written in lua for roblox al

Thanks for the feedback :grinning:

1 Like

Currently making semi-realistic arcadey feeling cars for my town/economy game. This system looks really clean in comparison to janky systems that use roblox physics based cars use. I don’t want to mess with attachments and constraints for hours just to get half of what I wanted. Can you give me pointers about how you’ve done this? I’ve been struggling to find a clean way to implement modular cars for my game. Any help appreciated!

1 Like

well I am not sure what you mean by economy, if you mean loading physics objects to the back of a truck then this approach might feel a bit janky since the system doesn’t account for objects falling under the wheel it acts mostly like a hovercraft with fake wheels, if it just something like press “e” to access vehicle storage it should be pretty okay

before starting here are some notes;

  • implement stuff the right way, not the fastest way, this will prevent you from drowning in technical debt

  • I have stopped developing this project since I couldn’t get the car to have consistent physics across varied frame rates (30-240) I managed to get the spring rates+grip levels consistent but couldn’t just get the “sway bars” to act right they were fine in 40-60 frames but anything not in that range would cause the car to jitter/shake/vibrate. (i think this is the reason why most front page racing games use physics constraints to have body roll or they just fake it)

  • ONLY ATTEMPT THIF IF YOU THINK YOU CAN SOLVE THE JITTER ISIUE

  • or just apply the force from the y level of the center of mass to not generate any body roll , this will result in a less interesting handling

  • Note that most Roblox tutorials about Raycast vehicles are extremely basic, I recommend using unity tutorials and translating code to work in Roblox

  • also I’ll assume you have intermediate knowledge of Roblox’s scripting language, also knowing a bit of c# would be really nice

  • I recommend understanding gearing(gear ratios etc) and sway bars before starting this

  • I also recommend you vehicle to be single part vehicle, the physics sometimes got weird
    when I used 2 parts (1 for the car body, 1 for the center of mass).

  • also have this open in a tab it can be useful

First the springs, I recommend this video

  • it uses the Hookes law to set up the springs
  • but I have changed some of the stuff instead of dividing by delta time I used this method
  • the way he implements wheel rotation is really weird imo I just used CFrame, and my method looks something like this:
  • also feel free to tweak the gravity for your liking default roblox gravity is a bit too much imo
  • each frame (4x)–> find wheel → set its position to hit position, the rotation to the cars rotation → apply the roll → apply steering rotations if they are the front wheels

Used this for the body roll

  • the reason that the formula looks so complex in this is bc it is made for the wheel colliders in Unity which is a headache to work with too, the formula is basically just
--the snippet from the post
travel_R= (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;

--my implementation
travel_R=springLenghts[i]/maxSpringLenght

/////////////////

For the tire friction, i used this

  • the code is in C++ (I think), the major thing that you need to know is “std::” is just math. function
  • for the pacejka formula use, use this to visualize it
  • recommend increasing the tire load based on how much the spring is compressed, this will make it so you can do “i n e r t i a d r i f t o
  • also watch this video it really helpful, especially the part after the tenth minute
function pacejka(slipAngleDegrees)
	local x = slipAngleDegrees;
	local B = 1;
	local C = 2.8
	local D = 1.6
	local E = 1.2
--this formula is from Wikipedia not that the game dev forum post found this to work better
	return	D*math.sin(C*math.atan((B*x)-E*(B*x)-math.atan(B*x)));/
end
  • also you will need automatic counter-steering (its not implemented in the video attached to this post yet watch this to understand what I’m saying look at the front wheels after exiting a corner)
  • This is optional but it makes the driving more accessible to younger audiences otherwise you actually have to be careful using the throttle to not oversteer, people that I’ve got to get them to test the handling always spun out and complained about it
  • I used this to calculate the angle for it
local a = carCenterMassPart.CFrame.LookVector*-1
	local b=a+carCenterMassPart.Velocity
	local angle=-1*math.deg(math.acos(a.unit:Dot(b.unit)))*math.sign(localVel_ONLYSTEER.X) 
	if math.abs(angle)>5 and localVel_ONLYSTEER.Z>10 and 
    carCenterMassPart.Velocity.Magnitude>5 and isReverse==false then
	print("help")
	steerInput+=angle
end

these were stuff that would have saved me tons of time if I knew them earlier

feel free to point out my mistakes I’ll try to answer anything that you ask sorry for the late reply

Also, PLEASE IF MANAGED TO FIGURE OUT HOW TO SOLVE THE JITTER ISSUE IN LOWER/HIGER FRAME RATES PLEASE TELL IT TO ME

have a nice day :grinning:

1 Like

Woah, this is a lot of stuff. I haven’t really used more complicated math on roblox to do anything because I never got to learning it and the most complicated math I’ve taken yet is geometry, so it’ll definitely take a bit to understand what’s going on here. Thanks for listing out everything you’ve learned.

1 Like

dont get scared about the formula, i dont even know how it works just tweak the values untill you get a good result i realy reccomand deesmos for that i have linked that up

1 Like

How did you implement the pacejka friction model, like how it is applied to the contact point? When i tried it usually ends up in the car jittering with friction making no sense, I may be doing something wrong in calculating the slip angle.

1 Like

Watch the gdc conference with “just cause 4” and find the section that shows how to do a friction clamp