Detect when player is hitting a wall

Im trying to script a custom movement system, I want to be able to detect when the player is and isn’t moving. I tried using humanoid.movedirection.magnitude but then realized that doesn’t take into account when the player is hitting a wall or colliding. Can anyone tell me how to detect when the player is moving while taking into account collisions?

1 Like

This goes in #help-and-feedback:scripting-support

1 Like

alright I changed it, could you help me with the wall detection?

why not detect when the wall gets touched?

@Tm00nandBack
do this

Screenshot 2023-10-29 194044

local wall = script.Parent
local player = game.Players.LocalPlayer

wall.Touched:Connect(function(hit)
	if hit.Parent == player then
		--do something here
	end
end)

tell me if it works

Probably because he’d have to put a script inside every single part that is possible to collide with. Bad practice and much more efficient to work with the player instead.

OP, have you tried using HumanoidStateTypes?

Assuming your movement system is being handled in some sort of RenderStepped event or while loop, you could always store their last position in a variable outside the loop, and get the magnitude of their current position with the last one. If the magnitude is less than some threshold then the player isnt moving

2 Likes