Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Rotate CFrame about an axis by theta?

Asked by
gladii 2
4 years ago

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

1 answer

Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
4 years ago
Edited 4 years ago

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

0
Hey, thanks for the commment. There are still some issues. The second answer doesn't really work, it produces a similar result to what I had. The first answer produces a different results. The cart rotates well, but on the wrong plane. Here is a video showing what happens with the first solution: https://streamable.com/ogczig . The cart is rotating "absolute" instead of "relative". gladii 2 — 4y
0
I had a similar initial solution to 1 at first, but I ran into the problem that is currently has which is why I tried to switch to something similar to 2. gladii 2 — 4y
0
Update: self.Cframe was being somehow overset by re-notating it later in the script. After notating it differently, it works now. thanks. gladii 2 — 4y
Ad

Answer this question