November 22, 2017, 01:04:27 AM

Author Topic: moveBy() is weird  (Read 1324 times)

sepharoth213

  • Newbie
  • *
  • Posts: 30
    • View Profile
moveBy() is weird
« on: June 06, 2013, 12:45:54 PM »
Couple things about moveBy() that I've worked around but I will probably work on fixing if I find the time:

  • It only calls moveCollide() for the first entity it collides with.
This is my biggest issue with moveBy, the way I'm currently working around it is really ghetto:
Code: [Select]
public override function update()
{
    var tempX = x;
    var tempY = y;
    moveBy(xSpeed, ySpeed, ["player"], true);
    x = tempX;
    y = tempY;
    moveBy(xSpeed, ySpeed, ["block"], true);
    super.update();
}
Since bullets can either move through the player that shot it or be removed when hitting the enemy player, this code works fine. But I shouldn't have to take the performance hit (however marginal) to do this. (which is probably why the disable collision feature isn't documented)
  • It won't move the entity at all if the current coordinate offset is less than .5
This doesn't sound like the worst thing in the world, but it causes some serious issues in platformers that have low gravity. It results in the player only colliding with the ground every 3~4 frames. My workaround is equally ghetto:
Code: [Select]
public override function update()
{
    fallingCounter += 1;
    if(fallingCounter >= fallThreshold)
    {
        onGround = false;
    }
    ySpeed += gravity;
}
public override function moveCollideY(e:Entity)
{
    if(ySpeed > 0)
    {
        onGround = true;
        fallingCounter = 0;
        ySpeed = 0;
    }
}
Once I put this in, it also made platforming more forgiving when trying to jump off of a ledge, so this didn't affect gameplay at all. It was just an annoying thing to deal with.
  • It will desync itself from integer values, causing weird one-off issues

Pretty simple workaround, but really confusing when it happened to me.
Code: [Select]
public override function moveCollideX(e:Entity)
{
    if(xSpeed > 0)
    {
        x = e.x - width;
    }else
    {
        x = e.x + e.width;
    }
    return true;
}
public override function moveCollideY(e:Entity)
{
    if(ySpeed > 0)
    {
        y = e.y - height;
    }else
    {
        y = e.y + e.height;
    }
    return true;
}

    Alright, that should help out anyone googling for these issues like I was. Thoughts?

    Matt Tuttle

    • Administrator
    • Sr. Member
    • *****
    • Posts: 309
      • View Profile
      • Matt Tuttle's Blog
    Re: moveBy() is weird
    « Reply #1 on: June 06, 2013, 12:50:50 PM »
    moveBy is a straight pull from FlashPunk. If you'd like to hack on it a bit and make it work with multiple collisions you can submit a pull request in GitHub, or just post it here. I think this sounds like a great addition and less "ghetto". ;)