Detect turning with ShiftLock enabled

I’m making a sliding game where turning sharply will start a drift, I can already do that with this code.

local MoveDirection = RootPart.CFrame:VectorToObjectSpace(Humanoid.MoveDirection) -- makes it relative to character
local MoveDirectionX = MoveDirection.X
if MoveDirectionX >= 0.55 then -- Drift Right
	-- drift right code
elseif MoveDirectionX <= -0.55 then -- Drift Left
	-- drift left code
end

Issue is, trying to use this code with first person/shiftlock will make the MoveDirectionX result in nothing being outputted (0).
I’ve tried ControlModule:GetMoveVector() as of now, is there a way to make the code above work with ShiftLock/First Person?
A and D inputs work just fine, it’s only moving and turning with shiftlock/first person that doesn’t get detected.

1 Like

Hey!

The issue is that with ShiftLock or first-person mode, Humanoid.MoveDirection doesn’t capture rotation input, so MoveDirection.X can be 0 even when the player is turning. To detect turning in ShiftLock, you need to track the camera’s rotation relative to the character instead of just MoveDirection. For example:

local camera = workspace.CurrentCamera
local rootCFrame = RootPart.CFrame
local lookVector = rootCFrame.LookVector
local camLook = camera.CFrame.LookVector

-- Compare character forward to camera forward to detect turning
local turnAmount = rootCFrame:VectorToObjectSpace(camLook).X
if turnAmount >= 0.55 then
    -- drift right
elseif turnAmount <= -0.55 then
    -- drift left
end

Key point:

In ShiftLock/first-person, input movement isn’t always in Humanoid.MoveDirection. Use the camera’s forward vector relative to the character to detect turning.

Hope my reply solved your issue, if it did, I’d greatly appreciate if you could mark my reply as solved.

1 Like

This worked for detecting the player moving with ShiftLock and both A and D keys, however I have a new issue: Using A and D keys will increase the turn amount more compared to ShiftLock, which isn’t what I wanted: Drifting has to be universal, regardless of using A or D keys or ShiftLock/FirstPerson
I have it set to print the turnAmount every frame for debugging.
Player using ShiftLock, turnAmount is generally low:

Player using A and D keys, turnAmount is higher than ShiftLock:

Just multiple one of them with a constant so it looks like the other. Physicists do it all the time.

2 Likes

Seems like I just need to multiply it by 10 then, cause usually its a decimal point lower for some reason :confused:

I assume you can also figure out the constant by dividing one metric with the other.

For example:
Metric 1: 2
Metric 2: 5

division = 2/5 = 0.4

if you multiply the second metric (5) with 0.4, you get the normalized value so it equals the first metric (2). Just take some samples and average to figure out the most optimal constant.

1 Like

Also just realised that moving the camera will cause it to register a drift, even if the character’s player isn’t turning.
As you can see, the TurnAmount changes when any change in movement is done to the camera.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.