So Lets say you are wallrunning to the right. Now in theory, It would only makes sense to tilt the camera to the left right? However, I wrote this code and it seems to print no errors however it seems like it’s not working. Here’s the code:
local camera = workspace.Camera
game:GetService("RunService").Heartbeat:Connect(function()
--wallrunning stuff
camera.CFrame = camera.CFrame * CFrame.Angles(0, 0, math.rad(45))
end)
As long as you’re not changing the CameraType of the camera then the rotation and position will either mess up or not even get changed. You could change the CameraType to “Custom” and then make some code so the camera will still follow the player. (Or you could just modify the default camera script) Because the current default camera script is still overwriting the cframe of the camera and the CameraType has not been changed, it does this.
You could use CameraType scriptable and then use a combination of upvector and -lookvector to offset the camera while keeping the same rotation as the character, which might look something like this
cam.CameraType = Enum.CameraType.Scriptable
local function lock_camera()
local hrp_cframe = hrp.CFrame
local new_cframe = CFrame.new(hrp_cframe.p + hrp_cframe.upVector * offset_up + -hrp_cframe.lookVector * offset_back) * hrp_cframe.Rotation
hrp.CFrame = new_cframe
end
I’m assuming your character is rotated when it wallruns.
No, It actually isn’t, however I did manage to get it down by looking it up a little bit on Devforum.
game:GetService("RunService").RenderStepped:Connect(function()
camera.CFrame = CFrame.lookAt(camera.CFrame.Position, camera.CFrame.Position + camera.CFrame.LookVector) * CFrame.Angles(0, 0, math.rad(angle))
end)
if (status == 0) then
status = 2
while (angle < 20) do
local t = game:GetService("RunService").RenderStepped:Wait()
angle = angle + rate * t
end
angle = 20
status = 1
end
Now how do I set the camera back to normal when the wallrun is done?
while i was writing the script, it threw a warning, Unknown global ‘tiltLeft’ (that’s what I named it), does it have anything to do with being an if/else statement?
You have to first define the connection variable and then the line under it actually set it to the connection else the disconnect line will still not have access to the connection variable.