How can I make the player look behind them while keeping the same character direction?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am trying to create a script that allows the player to look behind them without influencing the character’s movement direction AND allow the mouse to move the player’s character direction while offset. If you’ve played Evade, you may have noticed the feature to look back while running in the direction you were facing. I am trying to replicate that.

  1. What is the issue? Include screenshots / videos if possible!

I can’t seem to figure out a way to change the character’s direction with the mouse. The character will a certain direction all of the time.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve searched for a while looking for possible solutions. I could only find some that slightly helped me get closer to my goal, but not quite.

local oldOffset = CFrame.new(0,0,0)

local positionOffset = CFrame.new(-.4,0,-.2)

local rotationOffset = CFrame.Angles(0,math.rad(-165),0)

UserInputService.InputBegan:Connect(function(input, Processed)
	if Processed == false then
		if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.Q then
			
			KeybindsFolder:WaitForChild("LeanEvent"):FireServer(true, input.KeyCode) --part of a different script, ignore this
			
			camera.CameraType = Enum.CameraType.Track
			
			controlModule:SetRelativeCamera(false)
			
			camera.CFrame *= CFrame.new(-.4,0,-.2) * CFrame.Angles(0,math.rad(-165),0)
		end
	end
	
end)

UserInputService.InputEnded:Connect(function(input, Processed)
	if Processed == false then
		if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.Q then
			
			camera.CameraType = Enum.CameraType.Custom

			controlModule:SetRelativeCamera(true)

			KeybindsFolder:WaitForChild("LeanEvent"):FireServer(false, input.KeyCode) --part of a different script, ignore this
			
			camera.CFrame = oldOffset
			
		end
	end

end)

This is my code for the camera script.

1 Like

Edit: I removed the " controlModule:SetRelativeCamera(false) " line and it fixed the issue where the character would move in a certain direction every time, but this leads to the character moving towards the direction the camera faces, after it was offset.

I think you can just invert movement direction while camera is offset i found invert movement code on another post and here is how you can insert into your script

local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local player = game:GetService("Players").LocalPlayer -- Get Local Player
local PlayerModule = require(player.PlayerScripts:WaitForChild("PlayerModule")) --Get Player Module

local movementController = PlayerModule:GetControls() --Get Player Controls

local oldOffset = CFrame.new(0,0,0)

local positionOffset = CFrame.new(-.4,0,-.2)

local rotationOffset = CFrame.Angles(0,math.rad(-165),0)

UserInputService.InputBegan:Connect(function(input, Processed)
	if Processed == false then
		if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.Q then

			camera.CameraType = Enum.CameraType.Track

			movementController.moveFunction = function(player, direction, relative)
				player.Move(player, -direction, relative) --Reverse the direction by "-" it
			end

			camera.CFrame *= CFrame.new(-.4,0,-.2) * CFrame.Angles(0,math.rad(-180),0) --i changed Angles to -180 to completely turn behind but you can change back if it's not expected behavior
		end
	end

end)

UserInputService.InputEnded:Connect(function(input, Processed)
	if Processed == false then
		if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.Q then

			camera.CameraType = Enum.CameraType.Custom

			movementController.moveFunction = player.Move --Make player move in original direction

			camera.CFrame = oldOffset

		end
	end

end)

Post about inverted Control: How to make inverted controls? - #6 by Arbeiters

Result: 2022-10-25 19-40-41

This is the exact thing I was trying to replicate! Thank you.

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