1

Recently I am learning how to combine my collision system with advanced movement into my top-down "walking simulator" cart, when I often found my character "stuck" on the walls.

Cart #acc_movement_xb-0 | 2023-08-18 | Code ▽ | No License
1

Note: only applied advanced movement in X axis, while you can go through walls in Y direction in case of stuck.

Collision codes:

 ```function collid(x,y,con) local x1,x2,y1,y2=0,0,0,0 local cflag=0 if con==⬅️ then x1,x2,y1,y2=x,x-1,y,y+7 end if con==➡️ then x1,x2,y1,y2=x+7,x+8,y,y+7 end if con==⬆️ then x1,x2,y1,y2=x,x+7,y,y-1 end if con==⬇️ then x1,x2,y1,y2=x,x+7,y+7,y+8 end if fm(x1,y1,1) or fm(x2,y1,1) or fm(x1,y2,1) or fm(x2,y2,1) then cflag=1 end return cflag end```
 ```function fm(x,y,flag) return fget(mget(z\8,y\8),flag) --assuming solid flag = 1 end```

X-axis movement codes:

 ```function upd_pmove() p.x,p.y=mid(0,p.x,120),mid(0,p.y,120) --x:acc movement if collid(p.x,p.y,➡️)+collid(p.x,p.y,⬅️)==0 then if btn(➡️) then p.dx+=p.acc end if btn(⬅️) then p.dx-=p.acc end else p.dx=-p.dx end p.x+=p.dx p.dx*=friction p.dx=mid(p.dx,p.max_dx,-p.max_dx) ... end```

So, have you got any more adaptative collision to cope with that sticky situation? Or is there any improvement for the movement system? Post here if any!

-ThePixelXb_

P#114001 2023-08-18 05:02 ( Edited 2023-08-18 05:10)

1

Sometimes the most complicated solution isnt the best one.

I suggest switching to a simpler always-active-momentum based system. AAM is harder to implement, but once it works, you dont really need to tinker with it. here is a small cart i wrote using AAM.

Cart #aam_demo-0 | 2023-08-18 | Code ▽ | License: CC4-BY-NC-SA
1

The only catch with AAM, is that collision is very difficult to detect, but once you get detection and tile location down, it just works.

If you are set on using ACC, then you could modify it so that while moving, you set a minimum momentum so that you will always be bounced back from a wall instead of slowly slowing down untill you get stuck.

The reason you get stuck is because on collision with a wall, you reverse the momentum, but friction still lowers momentum untill you cant move anymore. try setting a minimum momentum while moving and also merge x momentum and y momentum because they are virually the same. make sure to add ACC to y movement or else your testing will be wonky.

P#133233 2023-08-18 19:42 ( Edited 2023-08-18 19:44)
1

You could also combine the two systems by creating a global momentum and remember the user's last input and move in that direction by adding momentum every frame by adding/subtracting from p.dx/p.dy like shown in my AAM cart.

P#133239 2023-08-18 20:08