So I reworked my CameraScript to integrate the character controller instead of using an independent part with AlignPosition and AlignOrientation. This required some modifying of the controller’s script to hold a little extra information and place some of its data in some ObjectValue
s, namely the lastHit
and fakeLastHit
values. I made sure to stay organized by commenting the modifications starting in pkg
and ending with an identifier.
pkg LastPart
I created a relationship between one part’s cframe in fakeWorld
and the other one in the real workspace using this formula:
(part.CFrame - part.Position) * (fakePart.CFrame - fakePart.Position):Inverse()
and I used this as the root angle for the camera. Usually, the lastHit
part and its fake counterpart is used, and it falls back to the HumanoidRootPart if the lastHit
part doesn’t exist. This is kept track of using ObjectValues
parented to the controller.
I figured out the ControlScript as well, so have fun moving freely between platforms and not getting frustrated because you’re at some weird angle.
I listed some pros and cons compared to the file in my last post:
Pros:
- The camera now rotates with parts you are standing on that are spinning on their Y-axis
- The controls synchronize perfectly with the camera’s movement, which means no more frustration with moving on spinning platforms.
- No extra part / aligning overhead, if that matters at all
Cons/New Bugs:
- the camera now spins by 180 degrees whenever you switch between a slope pointing towards the X axis and one pointing towards the Z axis and vice versa, but only while upside-down.
– This was what my last implementation was able to fix, by being independent from the character controllers. - This causes the camera to spin on meshes while upside-down as well.
- There is still a camera spin whenever there is a transition between an object staying still and an object spinning on its Y-axis, I think I only saw this while standing upside-down as well.
pkg CameraOffset (doesn’t work, addressing a bug)
I haven’t figured out a fix to this upside-down spin bug, but it will probably have to deal with more CFrame manipulation. I will have to understand how to detect when this spin happens though. I almost solved it inside the controller itself (with this package), but it only corrects itself when the character is completely upside-down.
Here is the playground file with the updated ControlScript:
playgroundCamera.rbxl (361.0 KB)
I have added a few keybinds for convenience, that being Tab for resetting movement and Left Ctrl for flipping gravity, which is a really fun feature by itself.
I also added just a few extra obstacles here and there to test out stuff, like stairs.