How to prevent camera pitch from affecting player movement vector?

What is my goal?
So I’m making a movement system and I have made a “wishdir” variable that outputs a vector3 depending on the players inputs. (i.e. if the player presses W, wishdir becomes 0, 0, -1 S it becomes 0, 0, 1 etc.) I’m working on making this vector3 relative to the player’s camera so movement is sensical.

The Issue:
My issue is that when the player moves their camera’s pitch, the wishdir moves with the camera. In the video provided you can visually see the wishdir as a blue line, and it’s relativity does work with horizontal camera changes. but I’d like to be able to nullify vertical changes without simply multiplying the Y of that vector by zero as I still want to be able to act on jump inputs (0, 1, 0)

What have I tried?
I’ve looked over the Devforum and haven’t found any solutions that don’t just multiply that Y value by 0.
If that is required, is there another way I can still include the jump input somehow?

My Code:
These are the important two lines that I think I have to add some math to somewhere but I’m not exactly sure where or how.

local camera = game.Workspace.CurrentCamera.CFrame -- grabs the Cframe of the player camera
 
	local newdir = camera:VectorToWorldSpace(wishdir) -- orients wishdir using camera and gives it to newdir

Any help would be greatly appreciated, thanks! :happy1:

local CameraDirection = workspace.CurrentCamera.CFrame.LookVector

local moveDirection = Vector3.new(CameraDirection.X,0,CameraDirection.Z).Unit

You shouldn’t update your move direction for jumps, you should actually just change AssemblyLinearVelocity

1 Like

You shouldn’t update move direction for jumping, because move direction applies speed at a consistent rate, and if you want reactive jumping, you cant use something like a VectorForce because that accelerates, you would have to accelerate up to 50, which takes time

That makes a lot of sense. Right now I’m using a LinearVelocity to move the character, would you recommend just using AssemblyLinearVelocity control all movement for this type of system?

1 Like

No. LinearVelocity for movement is fine, lots of games actually use acceleration for walking, but they set the velocity for jumping

Alright, thanks for the advice! I’m gonna start working on implementing this now.

The humanoid actually has a MoveDirection property that does the same thing I did

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