I alredy tried printing the value and the Y value for some reason is the same at one side and the other, is there a way to fix it?
local X,Y,Z = Camera.CFrame:ToEulerAnglesXYZ()
local CX,CY,CZ = Char.HumanoidRootPart.CFrame:ToEulerAnglesXYZ()
Mouse.Icon = "rbxasset://textures/MouseLockedCursor.png"
Char.HumanoidRootPart.CFrame = CFrame.new(Char.HumanoidRootPart.CFrame.X,Char.HumanoidRootPart.CFrame.Y,Char.HumanoidRootPart.CFrame.Z)*CFrame.fromEulerAnglesXYZ(0,Y,0)
1 Like
get the camera look vector then project the vector onto xz plane put this in startercharacterscripts
local Camera = workspace.CurrentCamera
local Char = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
local cameraLookVector = Camera.CFrame.LookVector
local characterPosition = Char.HumanoidRootPart.Position
local flatLookVector = Vector3.new(cameraLookVector.X, 0, cameraLookVector.Z).Unit
local newCFrame = CFrame.new(characterPosition, characterPosition + flatLookVector)
Char.HumanoidRootPart.CFrame = CFrame.new(characterPosition.X, Char.HumanoidRootPart.Position.Y, characterPosition.Z) *
CFrame.new(0, 0, 0, newCFrame.XVector.X, newCFrame.XVector.Y, newCFrame.XVector.Z,
newCFrame.YVector.X, newCFrame.YVector.Y, newCFrame.YVector.Z,
newCFrame.ZVector.X, newCFrame.ZVector.Y, newCFrame.ZVector.Z)
Mouse.Icon = "rbxasset://textures/MouseLockedCursor.png"
end)
1 Like
The direction the player is looking at is inverted, but i will try to figure that out, thanks
you can change the flatlookvector it should be like this
local flatLookVector = Vector3.new(-cameraLookVector.X, 0, -cameraLookVector.Z).Unit
1 Like
It did not work, but changing to negative the NewCFrame.ZVector.X, NewCFrame.ZVector.Y, NewCFrame.ZVector.Z)
almost did… but idk what happen to my character lol
i’ll use math.atan2 for camera let me know if there’s any issue with that
local Camera = workspace.CurrentCamera
local Char = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
local cameraAngle = math.atan2(Camera.CFrame.LookVector.X, Camera.CFrame.LookVector.Z)
local characterPosition = Char.HumanoidRootPart.Position
local newCFrame = CFrame.new(characterPosition) * CFrame.Angles(0, cameraAngle + math.pi, 0)
Char.HumanoidRootPart.CFrame = CFrame.new(characterPosition.X, Char.HumanoidRootPart.Position.Y, characterPosition.Z) *
CFrame.Angles(0, cameraAngle + math.pi, 0)
Mouse.Icon = "rbxasset://textures/MouseLockedCursor.png"
end)
1 Like
It Works, But I’m Still Think What In The World Happen There Lol
we get the camera’s look vector and use math.atan2 to calculate the angle it’s facing in the xz planes then we add math.pi 180 degrees to this angle to make the character face the same direction as the camera after that we create a new cframe that rotates the character to this angle while keeping the current position
1 Like
system
(system)
Closed
October 26, 2024, 6:47pm
#9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.