Hello, I’m uwuanims. I’m working on a Spider-Man game and am having trouble with my web wing system’s camera. For context, the camera controls the the character’s movement direction, but I’m having trouble constraining the pitch axis to 90 degrees in both directions. The resulting issue that’s causing is that the player can do loops and go in all kinds of skewed orientations. I’d greatly appreciate any help with this, the code that controls the camera movement is below as well as some details.
- The whole thing is run as a runservice connection
- I believe it’s due to the lerp causing overshoots with the camera, but I don’t know how to fix it.
- This is an issue that’s been plaguing me for a long time and is one of the main reasons I can’t get a test place out for my server.
local GlideForce:LinearVelocity = Character.GlideForce
local GlideOrient:AlignOrientation = Character.GlideOrient
local Delta = UserInputService:GetMouseDelta()
local mouseSpeed = Delta / DeltaTime
local clampedDeltaY = math.clamp(mouseSpeed.Y, -maxDelta, maxDelta)
local HRPCFrame = HumanoidRootPart.CFrame:ToWorldSpace()
AccumulatedYaw = (AccumulatedYaw - Delta.X * Sensitivity) % 360
AccumulatedPitch = math.clamp(AccumulatedPitch - clampedDeltaY * Sensitivity, -MaxPitch, MaxPitch)
print("Accumulated Pitch:",AccumulatedPitch)
local CameraOffset = HRPCFrame
* CFrame.Angles(math.rad(AccumulatedPitch), math.rad(AccumulatedYaw), 0)
* CFrame.new(GlideCameraOffset.X,GlideCameraOffset.Y,GlideCameraOffset.Z)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Camera.CFrame:Lerp(CameraOffset, CamTurnSensitivity * DeltaTime)
Edit 1: Anyone who helps me out with this will be put in the games credits because it’s so annoying XD