Issue with having movement relative to camera

Ok so I have rolling in my game. And I made it move relative to the camera.
Basically all I do is put a bodyvelocity in the character and set the direction to game.Workspace.CurrentCamera.CFrame.lookVector * Vector3.new(1,0,1)
I multiply it so that it does not include the Y value because obviously I dont want people rolling into the sky lol.
Anyways this causes an issue. If the camera is angled down or up the roll will be a lot slower since the lookvector is pointed away

Example of the issue:
https://gyazo.com/534c701b57e6b47a222bc61ea788b5e8
How could I fix this? Any help is greatly appreciated!

I guess a better way to explain my issue.
How I can make direction always face straight
e.g
This direction:
image
turns into this direction:
image

I am trying to lose the angle on the direction pretty much. Hopefully that makes it easier for anyone trying to help.

Unitize the vector, I believe you are missing that one step after setting the yAxis to zero.

1 Like

Try this

local function getWalkDirectionWorldSpace()
	local walkDir = camera.CFrame:VectorToWorldSpace( getWalkDirectionCameraSpace() )
	walkDir *= Vector3.new(1, 1)

	if walkDir.Magnitude > 0 then 
		walkDir = walkDir.Unit
	end

	return walkDir
end

Edit: Didn’t read the post above, my bad.

1 Like