I’ve made a movement script using linear velocity and I’ve run into a problem. How can I stop players from getting stuck against the walls when walking against it?
I’ve looked everywhere and I’ve heard of one possible fix and that being something called AABB, but I’m not sure how I would implement this.
Here are some variables that I think might be important:
local wishedDirectionRelative: Vector3 --W, A, S and D converted into Vector3
local wishedDirection: Vector3 --similar to wishedDirectionRelative but in world space, basically humanoid.MoveDirection
local currentVelocity: Vector3 --current character velocity
local currentVelocityRelative: Vector3 --currentVelocity relative to the camera direction
Hopefully someone could help me with my problem, because I would probably have to remove the movement if I don’t find a fix.
here is a video link that demonstrates my problem:
Ah, I had a similar problem to this, the solution is quite simple. Just go into the linear velocity and change the limit type to be axis based, then make it so that it does not affect your vertical velocity. Sorry I dont remember the exact names of these settings off the top of my head but you should be able to figure it out on your own really easily. The problem is that the linear velocity is trying to set your velocity to a vector on the xz axis, meaning the y component is 0. Since it is setting your velocity like this, it overrides the velocity due to gravity and you dont fall. If you are already doing this then Id suggest changing the collision of the character to a capsule shape by turning of character collision and adding an invisible capsule “collider” part. Then you can turn on custom physical properties on it and turn off friction, hopefully thatll fix it.
Instead of writing rootMover.MaxAxesForce = Vector3.new(math.huge, 0, math.huge) you should write something like:
local humanoidRootPart = workspace.elomala.HumanoidRootPart -- define the rootpart
local value = humanoidRootPart.AssemblyMass * 1000 -- edit 1000 with whatever value seems to work
rootMover.MaxAxesForce = Vector3.new(value, 0, value)
Setting the maxForce to math.huge makes the force very large, resulting in flinging and glitching against walls as shown in your problem. Instead, it is better to set the maxForce to a big number and not math.huge.
(you can just put in any number like 60000. The example just shows what i usually use)