You can write your topic however you want, but you need to answer these questions:
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.
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.
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)
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)