- Home /
Question by
H36615 · Aug 01, 2019 at 09:20 PM ·
collisioncollision2dwallhitbox
How to make sure object is always colliding a wall from multiple walls on top of each other during a wallslide?
Hello. I have these walls generated like these on top of each other. I have character that after hitting the wall, starts to slide down the walls.
Problem is that I have complex code which relies that during the slide down, there is always at least one wall colliding with the character. This is not the case though. At higher speed the issue occurs more frequently. I cannot think of a workaround. My pseudo code looks like this:
Update() {
if (press Jump && jumpEnabled) {
jump()
}
}
OnCollisionEnter2D(...) {
collidingWallsCount++
}
OnCollisionExit2D(...) {
collidingWallsCount--
if (collidingWallsCount == 0) {
// Here, sometimes, thinks that there is no more walls below, so can disable jump.
DisableJump()
}
So sometimes OnCollisionExit2D() is called before OnCollisionEnter2D() is called on newly collided wall (especially higher speeds). I even put gravity to bottom right so it's surely hitting every wall. Is there somehow a way to control the order of calling these methods? I only came up with not so pretty workarounds.
generatedwalls.png
(11.6 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612205911im_/https://answers.unity.com/themes/thub/images/avi.jpg)