I'm currently scripting the beginnings of a kart-racing game. Currently I can make the carts turn accurately when they are on level ground. I can't, however, figure out how to accurately make them turn on surfaces such as walls or hills. Intended behavior on surface with upvector == (0, 1, 0): https://streamable.com/c5h1ju Turning behavior on surface with upvector (1, 1, 0): https://streamable.com/q312n4
This is the code I'm using to turn the vehicle
local upv, theta = self.CFrame:ToAxisAngle() self.CFrame = self.CFrame * CFrame.fromAxisAngle(self.CFrame.UpVector, self.InputVector.X*step*self.TurningRadius)
This is being ran on renderstepped. Let me know if you have any questions about the code or anything else. Thanks, Gladii
you're multiplying the car's existing cframe, which is already tilted along the surface, by another cframe that's ALSO tilted along that surface
what you want to do instead is either 1. multiply the car's existing cframe by a cframe that just represents the turning or 2. create an entirely new cframe using the previous axis and angle plus the turning
-- 1 self.CFrame *= CFrame.Angles(0, self.InputVector.X*step*self.TurningRadius, 0) -- 2 local upv, theta = self.CFrame:ToAxisAngle() self.CFrame = CFrame.fromAxisAngle(upv, theta + self.InputVector.X*step*self.TurningRadius)
both methods work so you can use whichever you'd like