How to stop character from bumping into the wall like doors

  1. What do you want to achieve? Keep it simple and clear!

Im trying to make a local script that will stop the players from bumping into the walls.

  1. What is the issue? Include screenshots / videos if possible!

well it doesn,t working.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

yes i did look for the solutions and i tried it

-- Place this script inside the character or a LocalScript inside the StarterPlayerScripts

local character = script.Parent  -- Assuming this script is placed inside the character

-- Function to calculate velocity magnitude
local function getVelocityMagnitude()
	local HumanoidRootPart = character:FindFirstChildOfClass("HumanoidRootPart")
	if HumanoidRootPart then
		local velocity = HumanoidRootPart.Velocity
		return velocity.magnitude
	end
	return 0
end

-- Function to stop animations if velocity is too low
local function stopAnimations()
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local velocityMagnitude = getVelocityMagnitude()
		if velocityMagnitude < 2 then  -- Adjust this threshold as needed
			humanoid:Move(Vector3.new())  -- Stop movement
			humanoid.AnimationController:StopAllAnimations()  -- Stop all animations
		end
	end
end

-- Connect the function to the Heartbeat event to continuously check velocity
game:GetService("RunService").Heartbeat:Connect(stopAnimations)

im kinda new at developing so i think there is some fault in the script

2 Likes

Can you send a vidio of what you want like do you want the door to open b4 you toutch it or do you want you to physically not be able to toutch the wall

1 Like

The game Doors has a capsule model around the player which handles collision.

2 Likes

robloxapp-20240409-1312066.wmv (2.4 MB)

this is mine

robloxapp-20240409-1302567.wmv (3.3 MB)

and this what i wanted

i don,t know how to stop this camera movement or character bump, i think you get the idea

Ahh i see not sure of this would be janky or not but make a box around around the characters hitbox (you may have to change the dimensions to be bigger than the chars hitbox and when toutched check if its a part then then trigger a devounce check the boxes velocity you could say if its over a velocity then play your bump or the bump could be changed by the velocity, then do the bump and then once the bump is over re enable your script(sorry this is stupid long i cant write you a script cuz im going to school rn)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.