I feel like this is super simple, but I can’t figure it out
How do I get the walking direction of the player in local coordinates, so for example if the player is in shift lock mode and he moves left, no matter his orientation in the world I need it to print that he’s moving left. I’ve tried Part.Velocity, Humanoid.MoveDirection etc. but all of those are in world coordinates
You can also get the control vector by calling MasterControl:GetMoveVector(). MasterControl is a module located in PlayerScripts > ControlScript > MasterControl during run-time, unless you’ve overridden ControlScript.
EDIT: don’t do this, the PlayerScripts are changing structure so this isn’t best practice anymore.
For example, if you move forward on keyboard, the move vector will be (0,0,-1), and if you move to the side on keyboard it’d be (1,0,0) or (-1,0,0), or i.e. (1,0,1) if they are moving both sideways and backward. For mobile/controller, the vector would have variable length, as you have analog input there. The X/Z components show the movement direction. It’s also cross-platform.
The standard Roblox control script, unmodified, passes “true” as the second argument to Humanoid:Move(), so the moveVector is always interpreted in the camera’s coordinate space. In shift lock, this is also your character’s orientation, as they are forcibly aligned.
But when you’re not in shift lock, you need to pick what you mean by “local coordinates”. For example, if your character is running towards the camera, and you push the D key, they are going to move right in camera space, but from the character’s point of view it’s a left turn. So if you compare the character’s velocity against their humanoid root part orientation, it might not be what you want (you may want camera-relative “right”). Just something to keep in mind.
The second gotcha with using the moveVector directly is that it is only the desired movement direction; if your character is up against an obstacle, they can be stationary yet still have a non-zero moveVector. So, if what you really need to know is literally what direction they are moving, this is not enough information. In fact, you character can be moving in the opposite direction as the moveVector, since changes to velocity are not instantaneous in response to user input, it can take a few frames to reverse direction, for example. My advice would be to use the moveVector if what you care about is the user control direction, and use the character’s root part velocity if what you care about is actual movement direction and speed.