Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to know if humanoid is moving in the x, y or z plane?

Asked by
Ribasu 127
6 years ago

I don't care about the camera of the humanoid but about the humanoid's position in the world. The world is 3D: X, Y, and Z. How can I know if a humanoid is walking in the X plane, Y plane, Z plane or a combination of these? I need to take an action based on which dimension the humanoid moves...

0
A plane require two axes. I believe you are asking if the Humanoid is walking in the X, Y, or Z *directions*. Nevertheless, you can see the direction of movement by reading from the MoveDirection property of the Humanoid or the Velocity of the player's character's Torso (or UpperTorso if in R15). nilVector 812 — 6y
0
Technically, a humanoid does not have position or velocity or anything like that because it is not a part. The same goes for scripts, Values, folders and other stuff like that. However you could find the velocity/position of say the humanoid's head or other parts since these are parts. This would make it easier to tell the position and thus the direction the "humanoid" (even though it is not a par OBenjOne 190 — 6y
0
Hi, yes, I'm looking for the direction (is my player moving in the X or the Z direction?). I'll have a better look at your suggestions soon by implementing them! Thank you. Ribasu 127 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The location of the humanoid can be found from any object inside the NPC/Player that contains the "Position" property, such as base parts including the torso or head.

The Position property is a three-dimensional Vector3 with an X, Y, and Z coordinate.

If their position before was (0, 0, 0) and their position after was (3, 0, 10) then they moved on both the X and Z axis but mostly on the Z axis. If the Y axis increases, that means they're higher up than they were before.

A very basic version of what you're talking about could possibly look like this:

local model = workspace:WaitForChild("NPC")
local torso = model:WaitForChild("Torso")

local x = torso.Position.X -- the X position before it moved

-- wait for the humanoid to move, or maybe use the changed event on its position

if x ~= torso.Position.X -- if the current position and the original X position are not the same, then it moved
    -- do stuff?
end

That's probably not the best way to do it, but I'm not really sure what your goal is and it seems like you're not very familiar with Vector3 positions yet.

1
Checking for a displacement of a body over a certain period of time is the same thing as checking for the velocity, so it would be easier to read off of the Velocity property of the Torso (if 0 - not moving; if not 0 - moving). nilVector 812 — 6y
0
Agreed with @upVector Amiaa16 3227 — 6y
Ad

Answer this question