How to avoid player sliding on walls?

I’ve asked so many questions on DevForum I feel like people hate me

Anyway! On the project I’m working on the player moves on a 2D map with invisible walls at the sides, also, the player can look at the camera by pressing S

The problem is, when the player runs into a wall while looking at the camera, they start to slide and eventually go out of bounds

Like this!:

I’ve tried teleporting them back If they go too far away, but this is kinda displeasing fix, because the player SHOULDN’T be able to go out of bounds

please help
:pensive:

3 Likes

Hey, im not sure if this will disturb anything thats currently in the game, but i suppose it would be possible if you place another invisible wall infront of the camera basically blocking the player from going out of bounds.

fun-this-is-where-the-fun-begins

How about you try putting a BodyPosition inside of the character’s rootpart and then in a heartbeat loop set the BodyPosition’s Position to the characters position but the trick is to make that vector’s Z axis a static value of where your character is standing on the global Z before moving out of bounds

IN THEORY

This should work because BodyPosition will always try to make the position of whatever it’s parented too match it’s own Position

For example

local BodyPosition
local middleZAxisOfMap = 150
-- Would be in a heartbeat loop V
BodyPosition.Position = Vector3.new(root.Position.X, root.Position.Y, middleZAxisOfMap)
1 Like

This is a good idea! the problem is that bombs are supposed to fling the player around the map, and invisible walls would stop that from happening.

Hello again! This seems like a good method, I’m guessing BodyPosition = AlignPosition object?

The only problem I see in this is that it would also lock the players position when a bomb hits them, and they wouldn’t get flung.

There’s no reason to set up a heartbeat loop. If you set the maxforce of the other axis to 0 then it should only lock the Z axis.

1 Like

You almost were correct, if you mean creating the BodyPosition in a heartbeat loop obviously you dont wanna do that but if you want it to keep with the rootparts current position you need to set it in a loop, because if you set it just once and you try to move itll keep going back to the original positon you had set before; which isnt what @SharkRayMaster wants

1 Like

Nah its not AlignPosition use the old body mover BodyPosition literally would work great for what your trying to achieve and it’s simple

1 Like

You misunderstood what I meant, if you configure the maxforce in a certain way then it won’t result in that behaviour.

1 Like

So im curious when they get flung how does that work do they get flinged out of the bounds?

1 Like

image

You could use a PlaneConstraint. You can disable the PlaneConstraint when the bomb gets hit and re-enable it afterwards.

Oh wait I think I see what you mean so only apply the max force on the axis the is left and right according to @SharkRayMaster 's game and keep the other axis MaxForces to 0, this way itll always try to keep the Z axis in line while the other ones wont be effected

mb g

download

BodyPosition is deprecated so youll have to get it from toolbox but, if you dont wanna use deprecated stuff thats understandable you can do iit with other physics constraints but it just wont be as straightforward as with a BodyPosition, but anyway thats pretty much all you need too know to get it to work

Yes they get flung out of bounds but are reset to the correct position after, its a one time thing

Yeah so just do what I suggested with whatever physics constraint you feel comfortable, HELL try all of them if you want

Honestly I’m amazed I didn’t even know this object existed, I messed around with it abit and couldn’t get it to work but it was very interesting regardless

1 Like

Oh, could you please tell me why it didn’t work for you, so that I can continue to help you maybe? (with a video pls)

It’s hard to explain because I don’t know how PlaneConstraint works, but I cant adjust the max range of the constraint?

When I first used this object I had the same issue, but I forgot how I fixed it. I’ll check the documentation and let you know if I find something.