How to use VectorForce based on lookVector?

Hey !

I’m currently trying to write my own custom character controller however i’m having a problem rn.

To move my character i’m using VectorForce and to rotate the character i’m using AlignOrientation
Everything is working fine as you can see with this gif:

However i can only move based on the World Axis.
I want my player to be able to go to the direction where he is looking when he press W for exemple.
So i want my players to move based on his own axis.

I tried to change the relativeto parameters of VectorForce to attachement but i got some weird behavior of flinging. I know that by using lookVector i could probably be able to change the Force value however i’m using PID Contoller and idk how to use both at the same times.

So if you have any ideas or solutions it will be great to help me out !

Thanks !

How have you implemented the PID controller? It should still have a way to integrate a direction but if you had some code to show that would be great.

In terms of using the look vector, it pretty much is a vector with a net-value of 1 in the direction of the CFrame. You should be able to multiply this vector by the movement to get a force in the desired direction.

The camera’s look vector can be accessed using workspwce.CurrentCamera.CFrame.LookVector (I’m on my phone so might not be strictly correct but I’m sure you get the point)

@AstonAceMan is correct. I will elaborate more though. The Camera’s LookVector can be used for moving forward (though I would suggest removing the Y part of the vector so as not to be pushing into the ground). For going backwards, multiply the lookVector by -1, and then by the movement multiplier. For left and right, use workspace.CurrentCamera.CFrame.RightVector. Yet again, I’d remove the Y part of the vector, and for moving left, multiply it bey -1 first.

1 Like

Hey thanks for the answer so
for the force movement rn i’m doing this

i tried to multiply this vector3 by the lookvector however my character started to go super fast for no reason.

The outputx and outputz are both the value gotten by my PID controller