Heya there borther,
What do I mean by rolling with the environment?
Imagine this:
Wedge here is in your path, and you want to go up it.
Car here is what you use:
You need the car to angle itself so that it is perpendicular with the ground.
So it doesn’t hit the ground,
So it looks realistic,
But it wont work
Here have been my two methods:
- Reactive system
a. Detect when the front of the car is closer to the ground than back of car
b. Same applies to sides of the car
c. Roll/Add Angle to make them equal in size
d. (Optional) Make the speed of the roll scale with the height difference - Proactive System
a. Get the average of the normals of the rays from the front and back
b. Same applies to the sides
c. Then get the vector that is perpendicular to the new average
d. And set the body gyro’s cframe to look at that ray/vector
Weaknesses:
- Reactive: Wobbles like its nodding to some really dumb question
- Proactive: Can’t even get it to work
Here is the code I have for the proactive:
local function changeSteer(scal)
local stabFold = car.StabilityPoints
local rPoint = stabFold.RPoint
local lPoint = stabFold.LPoint
local fPoint = stabFold.FPoint
local bPoint = stabFold.BPoint
local fronAve
local sideAve
local _,_, fN = castRay(fPoint, (-1 * fPoint.CFrame.UpVector), hHeight.Value * 2)
local _,_, bN = castRay(bPoint, (-1 * bPoint.CFrame.UpVector), hHeight.Value * 2)
fronAve = (fN + bN)/2 --new method, lets see it
fronAve = Vector3.new(0, fronAve.Y, fronAve.Z).Unit
-- local _,_, rN = castRay(rPoint, (-1 * rPoint.CFrame.UpVector), hHeight.Value * 2)
-- local _,_, lN = castRay(lPoint, (-1 * lPoint.CFrame.UpVector), hHeight.Value * 2)
-- sideAve = (rN + lN)/2
-- sideAve = Vector3.new(sideAve.X, sideAve.Y, 0).Unit
local uFronAve = Vector3.new(0, fronAve.Z, -fronAve.Y).Unit
--change that, broth..
gyro.CFrame = CFrame.new(physRoot.Position, uFronAve)-- * CFrame.Angles(0, (-scal * tSpeed.Value), 0)
end
The code is integrated with the steering system but I’m just troubleshooting the stabilizer right now…