I have a wall running system in my game where it moves the players character along the direction of a normal of a wall.
If I wall run and the wall bends to the left, it does so accordingly and will move my character to the left along the wall. This is intended! However, I needed to change the camera behaviour to reflect the change that the character had (because rn it just stayed the same).
I thought of doing this by getting the change of the CFrame over time, which I did. However, this didn’t actually seem to do anything at all? Or at least, it wasn’t strong enough (I multiplied it by 100 and it jittered out but that meant it did affect it after all).
Here’s the function handling the camera wallrun behaviour:
local function updateWallrunCamera(character, deltaTime, rootPart, rotCFrame)
-- Update transition time for smooth blend
wallrunTransitionTime = math.min(wallrunTransitionTime + deltaTime, wallrunMaxTransitionTime)
local transitionAlpha = wallrunTransitionTime / wallrunMaxTransitionTime
-- Store wallrun direction from attribute and update character orientation
local wallrunDirection = character:GetAttribute("WallrunDirection")
currentWallrunDirection = wallrunDirection or currentWallrunDirection
rootPart.CFrame = CFrame.new(rootPart.Position, rootPart.Position + currentWallrunDirection)
-- Determine ideal wallrun camera rotation without affecting targetRotY
local wallrunRotY = getWallrunCameraOrientation(character, currentWallrunDirection)
local _, deltaRootCF, _ = (rootPart.CFrame * oldRootPartCF:Inverse()):ToOrientation()
print(deltaRootCF)
local wallrunRotCFrame = CFrame.fromEulerAnglesYXZ(rotationX, rotationY + deltaRootCF, 0)
-- Blend between user-controlled rotation and wallrun rotation
local blendedRotCFrame = rotCFrame:Lerp(wallrunRotCFrame, transitionAlpha)
-- Calculate and set the target camera CFrame
local targetCFrame = CFrame.new(rootPart.Position) * blendedRotCFrame * cameraOffset
local wrOffset = wallrunOffsets[character:GetAttribute("WallrunSide")] or Vector3.zero
CAMERA.CFrame = CAMERA.CFrame:Lerp(targetCFrame, wallrunSmoothness) * CFrame.new(wrOffset)
oldRootPartCF = rootPart.CFrame
end
I’m really confused. If you can suggest a different solution, go for it lol! All I really need is for blendedRotCFrame
to have the wallrun dir y and rotation y to combine so that the player can look around while wallrunning, but as soon as the wall bends the camera reflects it. Please help!