Acceleration & Deceleration for Tile-Based Platformer

Discussion in 'Programming' started by kpenrose92, Apr 16, 2019.

  1. kpenrose92

    kpenrose92 Member

    Oct 4, 2018
    Hey guys. I am making a platformer based on Shaun Spaulding's slopes for a tile-based platformer tutorial.

    My problem is: the way collisions are handled in this tutorial are making acceleration/deceleration (speeding up to a max speed while walking and slowing down to zero when stopping) seem difficult to code.

    I tried to give my player object some variable spd_accel (=0.1) to add to hsp (horizotal speed) until it reaches a certain maximum, like this:

    if (key_left)
    if (hsp>-1.5) hsp-=spd_accel*spd_walk;
    if (hsp<0) hsp+=spd_accel*spd_walk;
    if (key_right)
    if (hsp<1.5) hsp+=spd_accel*spd_walk;
    if (!key_right)
    if (hsp>0) hsp-=spd_accel*spd_walk;

    but here's a problem with this:

    the code for hsp in this tutorial removes fractions and adds them back in when they reach an integer value. I suppose this has something to do with the way collisions are handled in this model (tilemap_get_at_pixel, perhaps) and so when I add the fraction value spd_accel, it only results in a very choppy, not-accelerating player object.

    Anybody familiar with this predicament or have any advice to give?
  2. SoVes

    SoVes Member

    May 17, 2017
    I have a issue like this too, my acceleration works, but It's choppy.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice