How do you find out what direction someone is walking in relative to the camera? (Or, how do you find if someone is pressing two buttons at once?)

Hello, I’m trying to do some footplanting but I’m going the directional animation route instead of IK, because I feel like I have more control. How do you find out what direction someone is walking in (relative to the camera)?

What I mean is, how do you find out if someone is walking forward/backwards/left/right in the direction that they are facing? Also, how would you find the more complex directions like northwest, northeast, southwest, and southeast? I’m trying to do different leg animations for each 8 directions.

I know that you probably have to use Humanoid.MoveDirection, but I have no idea how to use it in my case.

Edit:
Since my game is shiftlocked, I could just detect what key they are pressing to determine the direction they are walking in. But, how would I find out if they are pressing two keys at once for more complex directions, like W and A, to check if they’re going northwest?

Do you mean in relation to the camera?

Yeah, that. Sorry, I didn’t know how to word it lol

How will you be doing the leg animations? and also what rig are you going to use r15 or r6

I’m using R6, and I’m making walk cycle animations for each direction a player walks in. It’s basically more accurate footplanting without IK.

Example: If the player is moving forward, then the forward walk cycle will play. if they are moving left, the walk cycle going in the left direction will play. If they move in a more complex direction like backwards and left, then the southwest walk cycle anim will play

One more question are you going to force shift lock enabled because without it players can only really walk in a forward direction. Your gonna most likely script your own control module which can be very difficult for new developers.

Yeah, my game is third person, shiftlock forced.
The camera is always in the direction of the mouse.

check if one direction key is pressed and set vector3 value for it. when you need to get the direction, you can just get all the vector3s added together.
for example, when w is pressed, add (1,0,0) to the vector3 and add(-1,0,0) to it when w is released.
and when d is pressed, add(0,0,1).
so when w and d are both down, the vector should be (1,0,1), which can be used to calculate the direction.

or another way without key binding, simply compare positions:

local prev = workspace.CurrentCamera.Position
local direction = Vector3.new(0,0,0)
game:GetService("RunService").Heartbeat:Connect(function(dt)
    direction = workspace.CurrentCamera.Position - prev
end)

Hope this helps!

3 Likes

That’s actually really smart! I was thinking of a system like that but by using variables that toggle true or false on inputbegan and inputended, and then by looking at which ones are true I could calculate direction. But, yours is way easier since Vector3s are literally directional values!