best system for tiled movment?

0 favourites
  • 3 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hi! I´m working with a tile based game,

    and although I{m making good progress, I hit a brick walk:

    I´m calculating movement using a variable AngleOfMovment for Each Unit(0,90,180,270)

    So if i want a unit to move left(the player samurai for example) I use a tween like this:

    AngleOfMovment: 180

    End X: Self.X + round(cos(Samurai.AngleOfMovement) * TileSize)

    End Y: Self.Y + round(sin(Samurai.AngleOfMovement) * TileSize)

    and for basic movement and collision detection it works great!

    But I´m implementing a lot of push and knockback mechanics, and that means that I sometimes need to get the opposite angle, and that is giving me a lot of trouble, because depending on the situation sometimes

    Self.X - round(cos(Samurai.AngleOfMovement) * TileSize)

    works, on others

    Self.X + round(cos(-Samurai.AngleOfMovement) * TileSize)

    this does, and I can figure out why, because both should add the opposite value right?

    If anyone has a more elegant solution, or a better way to get the opposite angle, I would be grateful.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think the correct formulas for opposite direction are these:

    Self.X - round(cos(Samurai.AngleOfMovement) * TileSize)

    Self.Y - round(sin(Samurai.AngleOfMovement) * TileSize)

    You can also use another variable - OppositeAngle.

    Set OppositeAngle to (Samurai.AngleOfMovement=0 ? 180 : Samurai.AngleOfMovement=90 ? 270 : Samurai.AngleOfMovement=180 ? 0 : 90)
    

    OppositeAngle will contain the angle opposite to the AngleOfMovement

  • Okay, that´s brilliant, thanks a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)