Log In  

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 ▽ | Embed ▽ | No License

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    
function fm(x,y,flag)
    return fget(mget(z\8,y\8),flag) --assuming solid flag = 1

X-axis movement codes:

function upd_pmove()

    --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


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!


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


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 ▽ | Embed ▽ | License: CC4-BY-NC-SA

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)

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

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-02-22 03:52:23 | 0.017s | Q:17