#Player Movement Independent of Current Camera

6 messages · Page 1 of 1 (latest)

cyan merlin
#

I'm creating a horror game reminiscent to the early Resident Evil and Silent Hill games, I've got the fixed camera system working; switching when the player enters areas of the map. But I seem to have encountered a problem when I switch the camera to a different angle—anything around 90 to 180 degrees, my character that was originally walking forward switches directions and turns the other way, away from the new camera when they should ideally be walking towards it.

I don't have any code started at the moment but I'm guessing this has more to do with the player and their movement rather than the camera?
I'm primarily a modeler, with little to no coding experience, although it would be helpful if anyone were to guide or point me to a direction of where I can start to implement what I'm trying to make.

Feel free to ask me questions! ^^

jagged widget
#

Change the cameratype

#

It's probably "following"

cyan merlin
#

StarterGui>CameraTriggers LocalScript

local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local Head = Character:WaitForChild("Head")
local TouchesFolder = workspace:WaitForChild("CamEvents")
local CamsFolder = workspace:WaitForChild("Cameras")

local touchCameraPairs = {
    ["CamEvent_DormCommon"] = "Cam_DormCommon",
    ["CamEvent_DormCommonShowers"] = "Cam_DormCommon",
    ["CamEvent_DormStairway_F1"] = "Cam_DormStairway",
    ["CamEvent_DormStairway_F2"] = "Cam_DormStairway",
    ["CamEvent_DormToilets"] = "Cam_DormToilets",
    ["CamEvent_DormShowers"] = "Cam_DormShowers",
    ["CamEvent_DormShowersToilet"] = "Cam_DormShowers",
}

local currentCameraPart = nil

local spawnWithSpawnCam = false -- Set it to "true" if you wanna Spawn with SpawnCam 
--and false if you wanna spawn with normal Roblox Camera

local function updateCamera()
    if currentCameraPart then
        local cameraPart = CamsFolder[currentCameraPart]
        if cameraPart then
            local cameraPosition = cameraPart.Position
            local lookAtPosition = Head.Position
            local newLookVector = (lookAtPosition - cameraPosition).unit
            local newCFrame = CFrame.new(cameraPosition, cameraPosition + newLookVector)

            Camera.CFrame = newCFrame
        end
    else
        Camera.CameraType = Enum.CameraType.Custom
        Camera.CameraSubject = Character
    end
end

local function onTouch(touchPart)
    if touchPart.Name == "End" then
        currentCameraPart = nil
    else
        local cameraPartName = touchCameraPairs[touchPart.Name]
        if cameraPartName then
            currentCameraPart = cameraPartName
        end
    end
end

for touchPart, _ in pairs(touchCameraPairs) do
    local part = TouchesFolder:FindFirstChild(touchPart)
    if part then
        part.Touched:Connect(function()
            onTouch(part)
        end)
    end
end

local endPart = TouchesFolder:FindFirstChild("End")
if endPart then
    endPart.Touched:Connect(function()
        onTouch(endPart)
    end)
end

if spawnWithSpawnCam then
    currentCameraPart = "SpawnCam"
end

updateCamera()

game:GetService("RunService").RenderStepped:Connect(function()
    updateCamera()
end)```
cyan merlin
#

I'm fairly certain that it would be better to alter the player's movement rather than the cameras as it would probably be redundant to change every single camera rather than just the player character itself.