So I’m trying to make my own movement system using the camera and a BodyVelocity object, but for some reason it’s not working correctly and I can’t wrap my head around why.
I’m trying to use the Pythagorean theorem to calculate the X and Z velocity, using the camera’s Y rotation as theta. Here’s the script:
local cam = workspace.Camera
...
-- Everything below this line fires whenever the W key is pressed.
local rot = Vector3.new(cam.CFrame:ToEulerAnglesXYZ()).Y
local xVel = math.sin(rot) * 16
local zVel = math.cos(rot) * 16
walkForce.Velocity = Vector3.new(-xVel, 0, -zVel)
I know I’m definitely doing something wrong here because whenever I rotate the camera along the X/Z axes, it affects the output of both xVel and zVel. I’m gonna assume from that alone that there’s probably some 3D wizardry going on that I can’t grasp (or I’m probably just stupid)