I’m trying to make a vehicle that sticks to the underlying terrain. This is the script i’ve come up with which uses CFrame.lookAlong()
to make the vehicle look forward and face the raycast’s normal but for some reason it’s not working.
game:GetService("RunService").RenderStepped:Connect(function(dt)
if not seat.Occupant then return end
local steer = CFrame.Angles(0, math.rad(3 * 0.1) * -seat.Steer, 0)
local shift = body.CFrame.LookVector.Unit * 0.1 * seat.Throttle
local front = body.CFrame:PointToWorldSpace(Vector3.new(0, 0, -(body.Size.Z / 2 + 5) * seat.Throttle))
local raycastResult = workspace:Raycast(front, front - Vector3.new(0, 1, 0) * 300 - front, raycastParams)
if not raycastResult then return end
body.CFrame = CFrame.lookAlong(body.Position + shift, body.CFrame.LookVector.Unit, raycastResult.Normal.Unit) * steer
end)
This is how it currently behaves and as you can see it doesn’t rotate up when driving on a dune. The random color sticks are the raycast normals and the red dots are the raycast origins.