So I'm trying to create animated axle suspension for an RC car that I'm trying to make.
I've attached a link to the RC car. The axle suspension code is in the FL wheel only.
When you start, it looks fine, but when you start driving it, it goes up and down and all around! I'm pretty sure cause it acts on the X and Z axis only, but I'm not sure on how to make it work only on the Y axis, cause that's the axis where the wheels go up and down.
Code by @ToldFable on devforum, modified by me:
-- define some variables CharPart = script.Parent.Parent.Phys Hinge = script.Parent.Chassis RootPart = Hinge.Parent while wait() do -- define position of origin HKpos = Vector2.new(RootPart.Position.X,RootPart.Position.Z) -- define position of target XYpos = Vector2.new(CharPart.Position.X,CharPart.Position.Z) -- the ratio to get the triangle's width over the height ratio = (XYpos.Y-HKpos.Y)/(XYpos.X-HKpos.X) beta = math.atan(ratio) -- converting this to radians -- turn it from radians into degrees beta = beta*(180/math.pi) print(beta) Hinge.TargetAngle = -beta -- beta has to be negative so it points at you end
Model to explain in further detail: https://www.roblox.com/library/7418794485/table-wedges