#Problem with deceleration and collisions

6 messages · Page 1 of 1 (latest)

outer needle
#

you're only checking 1 pixel in front for your collision, regardless of your speed

#

so if you're moving any faster than 1 pixel per frame, you're gonna overlap

#

you need to check your speed ahead, not a flat number

#

and acceleration needs to happen first, or you could be going faster than the distance you checked when you move

#
    if (dir_h != 0) {
        speed_h += acceleration*dir_h*dt;
        speed_h = clamp(speed_h, -max_speed, max_speed);
        moving = 1;
    }else if (speed_h != 0) {
        speed_h = approach(speed_h, 0, deceleration*dt);
    }
if (place_free(x+speed_h, y)) {
    x += speed_h;
}else {speed_h = 0;}``` something like this
#

do acceleration first, then check speed_h ahead for movement