I want to create a navball like in KSP. For those who don’t know what that is, it’s a ball that orients depending on what orientation your vessel is. I’ve attached a screenshot to help you get the idea.
It works-ish. It does point in the direction you’re going, but sometimes it suddenly flips when you’re orienting your vessel. (east turns into west, very bad!)
I’ve looked in the devforum to no avail.
Video of the issue (bottom right is the navball, in the properties menu is where you can see the orientation of the navball if that could help.):
while task.wait() do
local x = cap.Orientation.X
local y = cap.Orientation.Y
local z = cap.Orientation.Z
navball.Orientation = vector.create(x,y,z)
end
In theory, this should work, yet it doesn’t. Any ideas as to why this could be happening?
Without looking into details of your situation - my first guess would be that this might be an issue with rotation/orientation values being capped between 180 and -180, rather than being 0 to 360, could this be the case here?
Depending on which of the things gets capped (when you retrieve the value or when you assign it, I’m not sure since it’s been a while since I’ve seen this), you want to normalise the angle to be 0 to 360 instead (e.g. 360 - angle in case the angle is below 0).
I’m not totally sure what’s causing the issue, but it might have something to do with how the aircraft’s orientation is being calculated. I noticed the jump happens when the navball’s Z rotation goes from around 90 straight to -90, which seems like it could be part of the problem. Not sure if that shift is intentional or not. I also noticed that after it flips to -90, the values keep “increasing” — like going from 88 to -91, then -94, -102, and so on. I could be wrong, but that’s what it looks like.
local function to360(angle)
print((angle + 360) % 360)
return (angle + 360) % 360
end
while task.wait() do
local x = to360(cap.Orientation.X)
local y = to360(cap.Orientation.Y)
local z = to360(cap.Orientation.Z)
navball.Orientation = vector.create(x,y,z)
end
The video that was in my main post shows me having the navball selected, so it seems that the navball is being capped.
This is the function I made to turn it into a 0-360 range value, but it doesn’t look like it’s applying to the navball, as I get the same issue.
I applied the fix, but it still seems to be capped at 180. I’ve seen other games on roblox (e.g Space Sailors) do this flawlessly, so I know it’s possible, but it’s oddly difficult. Any idea if CFrames could help in this scenario?
CFrame would probably help this I think, but as a sanity check, I’m going to ask: can you not simply set the navball.Orientation to cap.Orientation? Is there a reason you are deconstructing them into x, y, z in the first place?
I’m deconstructing them just in case my rockets models are incorrectly oriented (for example, i want it to start off at 0,0,0, but sometimes it could be oriented like 0,-90,0 due to my horrible decision making skills while modelling). But yeah, you’re right, I could do that if my rockets were correctly oriented all the time
Ah, I had this as a MAJOR problem when I was making ships that float correctly on a bone-based sea mesh. I would honestly just experiment with how you have to rotate the model in its entirety in blender (or other software) in order to get the import as 0, 0, 0 in its starter orientation, it potentially makes a lot of things easier :).
First of all, you should just be setting navball.CFrame to be cap.CFrame.Rotation, but honestly I don’t think I have enough context to know the exact solution to this. You should probably print both CFrames (the cap and the new navball one) every couple of frames to debug.
Thanks for telling me about the rotation thing! Looks cleaner. What I meant to say earlier is that I wanted to just swap the x and z axis of the CFrame, if possible. (pitch, aka. up and down is supposed to be on the z axis, not the x axis)
You can just multiply with CFrame.Angles(), I’m pretty tired so might be wrong but off the top of my head that would be CFrame.Angles(0, math.rad(90), 0)
Why are you trying to use Orientation instead of copying the CFrame from the craft to the navball? Orientations have poles and they are derived from the CFrame.
I’m currently trying to convert this system to CFrame. Small issue, however: The x and z axis are incorrect. They need to be swapped, but everything else works fine.