I’m trying to build a space shuttle game where you can land the actual space shuttle itself.
The flying and all works great but I need some advice on how I should make the camera.
Right now, I am not modifying the camera at all while flying, it looks like this:
The problem is that when the plane rotates, the camera stays still, resulting in a weird-looking angle.
So my goal is to have a camera that stays still relative to the rotating plane but is still controllable by the player.
Any advice on how I should do this?
That’s the way I’m doing it right now, but the player must still be able to look around.
When you set it to a part’s frame inside the vehicle and set the camera type to scriptable, you won’t be able to move the camera like you would be able to in first person.
Ah I misunderstood. Unless there really is a property of Camera that I’m unaware of, one solution might be to simply update the Camera’s CFrame each time the vehicle is rotated. Something like this:
Right now I’m just setting the CFrame to some part of the vehicle every heartbeat which works I guess.
Maybe if I modify this CFrame by multiplying it with some mouse look vector it would kinda work.
I’ll see if this works lol.
You might have to make your own first person code that keeps track of the look yaw and pitch. This is only annoying because you’d like it to behave identically to the default first person camera. If you do this, you can then multiply the vehicles CFrame by a CFrame made up of this yaw and pitch, that will rotate your look direction into the vehicles space:
local cameraCFrame = vehicleCFrame * CFrame.fromEulerAnglesXYZ(userPitch, userYaw, 0)
Lerping the Camera’s CFrame mimics legitimate camera movement as if you were in first person. You end up with a bit of a “wobble” but you can call it turbulence
Couldn’t get it to work on my plane, it just locks to the plane’s camera starting CFrame.
Mouse movement does look pretty smooth though, and a little turbulence adds to the realism!
How exactly are you implementing this code?
So, there are a lot of ways you could do this. I think the easiest way would be to use the LocalToWorld function. This is the function used to find the absolute position of a part. You could use this function to find the absolute position of the part that the camera is parented to, and then move the camera to that position. local camera = workspace.CurrentCamera
local cameraParent = camera.Parent
local cameraPosition = cameraParent.Position
local cameraAbsolutePosition = cameraParent.CFrame:PointToWorldSpace(cameraPosition)
camera.CoordinateFrame = CFrame.new(cameraAbsolutePosition)