I have already tried Humanoid.MoveDirection.Magnitude > 0, But it seems to still detect movement even if the player is running into a wall.
Record the player’s current position, then using RunService.PostSimuation, compare the previously recorded position to the player’s new position. If they’re not fuzzy-equal, then you can count that as significant movement. Update the current position at this time. This is not the same as having a one-line if-statement for checking movement. You can run code within your PostSimulation
event handler, use a callback, or update a value for read-in
Alright, i’ll try this when i get home, thanks.
Not to be a bother, but how would i compare two vectors?
that’s because checking if the magnitude is over zero means that even the slightest movement will be registered. You should check if the magnitude is over 0.5 or 1, depending on how sensitive you want it. Just experiment with different numbers until you find one that suits you
You can use Humanoid:GetState() every heartbeat to check the movement
There is no idle movement state for humanoids. Whether still or moving, you’re in the Running HumanoidStateType
local distance = (currentPosition- lastPosition).Magnitude
order doesnt matter
or you can do
local standingStill = currentPosition:FuzzyEq(lastPosition) -- true/false
Is this how i should implement it? I’m still an amateur at scripting, and i’ve only ever used runservice.renderstepped before.
--!strict
local RunService = game:GetService("RunService")
local XZ_FACTOR = Vector3.new(1, 0, 1)
local MAGNITUDE_THRESHOLD = 0.1
local Character = script.Parent
local HumanoidRootPart = Character.HumanoidRootPart :: BasePart
local previousPosition
local function getCurrentPositionXZ(): Vector3
return HumanoidRootPart.Position * XZ_FACTOR
end
local function onPostSimulation()
local newPosition = getCurrentPositionXZ()
if not previousPosition:FuzzyEq(newPosition, MAGNITUDE_THRESHOLD) then
previousPosition = newPosition
print("Moving!")
end
end
previousPosition = getCurrentPositionXZ()
RunService.PostSimulation:Connect(onPostSimulation)
```
use character:GetPivot().Position or character.HumanoidRootPart.Position (first checking if it exists) for the position
then get rid of everything in the task.spawn
set the prevpos to currentpos AFTER the code you have in the postsimulation function, so that the current pos in the current loop becomes the previous position in the next loop