You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to create a suspension system for a 4 wheeled car, using raycasts and body thrusters. I have done a good amount of research on the topic, but I am having a hard time grasping everything. And mu car goes all over the place. -
What is the issue? Include screenshots / videos if possible!
Imgur: The magic of the Internet
https://i.imgur.com/hh6ALZl.png
https://i.imgur.com/xWsjAKw.png -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked through many dev posts, scripts from the toolbox, and wiki articles on spring physics, but I cant grasp it
- I am basing this off of my research on ‘Jailbreak’ cars. I like the simple set efficient suspension on them.
- I dont necessarily need any code, but formulas at least would be helpful
Car Script:
local car = script.Parent
local config = script.Parent:WaitForChild("CarConfig") --Just some basic physics settings for the car. See 'while true do'
local run = game:GetService("RunService")
local thruster_hub = car:WaitForChild("Body"):WaitForChild("Base") --The parent of all the body thrustsers.
local thrusters = thruster_hub:GetChildren() --Put all of em' in a table
local base = car.PrimaryPart --the base part, AKA PrimaryPart of the car model
local last_pos = base.Position --The last 'frame' position of the base
while true do
run.Heartbeat:Wait()
--Physics stats. see 'config' - line 2
local stiffness = config:GetAttribute("SpringStiffness")
local wheel_rad = config:GetAttribute("WheelRadius")
local height = config:GetAttribute("Height")
local dampening = config:GetAttribute("Dampening")
--Loop through each thruster and apply the physics
for i,v:BodyThrust in thrusters do
local origin = v.Location + base.Position --origin of raycast (based on base pos and body velocity location)
local raycast = workspace:Raycast(origin,-base.CFrame.UpVector*(wheel_rad+height),RaycastParams.new())
if not raycast then continue end --prevent errors ;)
local stiff_stiff = (height-raycast.Distance) * stiffness --the stiffness calculator. I think this is right, but i am not 100% positive
local force = stiff_stiff - (base.Position.Y - last_pos.Y) * dampening --the issue it the last part. i cant figure out dampening
v.Force = Vector3.new(0,force,0)
last_pos = base.Position
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.