Helwdrokin Posted March 10, 2025 Share Posted March 10, 2025 i tried to search in the forums to see if someone didn't asked this before, maybe i didn't used the right key words, so sorry if this question have been asked before i tried to use a function to get the player position in a frame, and compare with the last frame position to check for movements. It worked great until i joined multiplayer server. so now i'm asking, is there any function on the game that's just check if the player is moving/standing? Link to comment https://forums.kleientertainment.com/forums/topic/164770-how-to-detect-if-player-is-moving-on-client-mod/ Share on other sites More sharing options...
oregu Posted March 10, 2025 Share Posted March 10, 2025 (edited) serverside (just putting this here for future reference): Spoiler --if inst:GetBufferedAction().action.id == "WALKTO" then -- is trying to walk somewhere in the world (not as good as i thought) -- --end if inst.components.locomotor.isrunning then -- is moving using locomotor end isrunning is most accurate clientside: Spoiler local recordedpoint local dt = 0 -- maybe try GLOBAL.FRAMES if what ur doing is animation based? inst.movingtask = inst:DoPeriodicTask(dt, function() -- note: only works for players local currentpoint = inst.components.areaaware.lastpt if recordedpoint and currentpoint ~= recordedpoint then -- checks if last point is the same (you have to periodically check with this) -- do smth end recordedpoint = currentpoint end if inst.HasTag"moving" then -- in a running animation (likely less resource intensive but player could be running into a wall) -- do smth end The first method only tracks position, so a player will be counted as moving even if theyre being pushed. There's also checking with running animstates but there's so many running animstates that I'm not sure. i think moving tag covers most of them though. Edited March 10, 2025 by oregu 1 Link to comment https://forums.kleientertainment.com/forums/topic/164770-how-to-detect-if-player-is-moving-on-client-mod/#findComment-1806068 Share on other sites More sharing options...
Helwdrokin Posted March 11, 2025 Author Share Posted March 11, 2025 thanks @oregu, the inst:HasTag("moving") worked i tried to check player position similar to your second example, then i realized that using addPlayerPostInit() messed up the function, each player on the screen was doing the position check and then messing up the function Link to comment https://forums.kleientertainment.com/forums/topic/164770-how-to-detect-if-player-is-moving-on-client-mod/#findComment-1806119 Share on other sites More sharing options...
oregu Posted March 11, 2025 Share Posted March 11, 2025 (edited) I'd recommend making a component for this if this servers a higher purpose, but this is OK for something small. I think I recorded the position wrong. So I redid the fn. Spoiler AddPlayerPostInit(function(inst) local dt = GLOBAL.FRAMES * 3 -- not sure why 3 frames is the correct buffer for this, increase if u have issues inst.movingtask = inst:DoPeriodicTask(dt, function() -- note: only works for players, and wont work if player is unloaded local currentpoint = inst.components.areaaware.lastpt if inst.recordedpoint and currentpoint ~= inst.recordedpoint then inst:AddTag"moving2" --print(inst, "moving") else inst:RemoveTag"moving2" --print(inst, "not moving") end inst.recordedpoint = GLOBAL.Vector3(GLOBAL.unpack{currentpoint:Get()}) end) end) Edited March 11, 2025 by oregu 1 Link to comment https://forums.kleientertainment.com/forums/topic/164770-how-to-detect-if-player-is-moving-on-client-mod/#findComment-1806129 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now