How would I make the player follow a relative CFrame rather than the CFrame of the camera?

I want you to get the PlayerModule and I want you to make it so that…
DO you know how the player character always moves away from the camera when you press W ?
Image

This script here is for cutscenes and certain events.
I was thinking underneath ‘temporaryCFrame’ I should require the Controller module and set it such and such

I want it so that during the cutscene, the player presses W and moves away in the direction of temporaryCFrame rather than the camera

this is because sometimes the game will show a cutscene where a bridge is collapsing and if the camera shows the bridge from the side then the players will fall off it since they always move relative to the camera

What I have tried to do is access the player module and then I hardcoded so that the character doesnt move relative to the Camera but that only causes it to move along the whole world axis.
What i want to do is define a certain CFrame instead of the world axis yknow. That would make it much better for scenes where a player is escaping a burning building and all they have to do is press W

THis is an example why i need the following above

The character is following a great path along the bridge by pressing W until the camera switches to that specific view
but i would like to define a specific CFrame to keep them following that same path yknow?

1 Like

You can modify Roblox’s PlayerModule script for this. There’s a key called “moveVectorIsCameraRelative” whose value is a boolean value (true/false). By default, it is true. You would just set the value to false:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerScripts = Player:WaitForChild("PlayerScripts")
local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))

PlayerModule:GetControls().activeController.moveVectorIsCameraRelative = false

Whenever you want to return it to how it usually is, you just set the value to true.

2 Likes

Yes but the issue is this sets it relative to the world space CFrame.

I want my own CFrame relative

1 Like

After thinking about it overnight, I realized you could probably just use VectorToWorldSpace for this. You would first get the player’s movement vector, get the CFrame of the player at the time the camera changes, and then manually update the movement on RenderStepped.

local players = game:GetService("Players")
local player = players.LocalPlayer
local playerScripts = player:WaitForChild("PlayerScripts")
local playerModule = require(playerScripts :WaitForChild("PlayerModule"))
local character = player.Character or player.CharacterAdded:Wait()
local humanoid  = character:WaitForChild("Humanoid")
local runService = game:GetService("RunService")
local moveConnection

-- Put this part in the block of code that also changes the camera's cframe
local currentPlayerCFrame = character:GetPivot()
moveConnection = runService.RenderStepped:Connect(function()
	-- Get all components needed
	local moveVector = playerModule:GetControls():GetMoveVector()
	local direction = currentPlayerCFrame:VectorToWorldSpace(moveVector)
	direction *= Vector3.new(1,0,1)
	-- Update the movement manually
	humanoid:Move(direction)
end)

Whenever you want it to return back to being relative to the camera, you would just disconnect the connection:

-- Whenever you change the camera back to normal
moveConnection:Disconnect()
1 Like