I’m currently experimenting with an old raycast car project I used to work on, and I’m stuck at CFraming the wheels to be above the ground and rotate.
The wheels have to be in line with their respective attachment (e.g. front attachments can rotate, thus the wheels turn around yaw axis). But they also have to turn around the pitch axis as the vehicle moves forward/backward.
This is where I simply got stuck:
- Set the Wheel’s position to Attachment.WorldPosition
- Align only the wheel’s Y-orientation with the attachment’s Y-orientation
- Rotate the wheel by RotValue (deg.) on its pitch.
- Repeat
This is what I tried, and it doesn’t work regardless if its placed in the X or the Z position, so I’m open and will appreciate any help:
Spring.Wheel.CFrame = CFrame.new(StaticSpringAttachment.WorldPosition) * CFrame.fromOrientation(math.rad(Spring.Wheel.Orientation.X), math.rad(StaticSpringAttachment.WorldOrientation.Y), math.rad(Spring.Wheel.Orientation.Z))
local RotValue = (((Spring.Wheel.Position - LastPositions[Spring.Name]).Magnitude) / circ) * 360;
Spring.Wheel.CFrame *= CFrame.Angles(0, 0, math.rad(RotValue))