How do I make sprite travel up and down blocks?

  • I Have these tiles and sprites. The sprites have to traverse these tiles that vary in height, so the sprites have to travel up and down these tiles but I've got no clue how to fully put them over a tile or how I would make them abide next to the tile if they were going down. They could just fall down but the main problem is having them go up, something like a ladder but this is a wall kind of ladder.

    Here's an example image of what I mean:

    And here's the Capx:

    https://www.dropbox.com/s/j9smbimeijc6e ... .capx?dl=0

  • Happy hopping.

    https://www.dropbox.com/s/dfslpz0bodod3 ... .capx?dl=0

    Wow! Thanks but that's not exactly how the sprites should move along the terrain.

    Let's see if this clears things up:

    The sprite goes straight until it reaches a tiles that is either taller or shorter than the one it's currently on. If it's taller, then the sprite climbs up it to scale it. If it's shorter, then the sprite climbs down it and continues straight until it goes to another tile that is not leveled.

  • bump

  • Will they always be traveling to the right or will they also be going left sometimes as well?

    I have an idea how to make it work - and should even work with terrain that's moving up or down, but implementation will be a bit different depending which way the sprites are moving. If always to the right it will be a bit easier, but if they need to go both ways it will be a little more tricky.

    Basically you will need an instance variable for each sprite, let's call it "direction". You will then need to set this instance variable to either "up" "down" "left" or "right" (or 1,2,3 or 4) using conditions - then set the movement in the desired direction based on the variable value. You will need a second variable for which *general* direction it's heading (left or right) if the sprites can move both ways. This second variable will act as a secondary condition check.

    Pseudo code:

    ----------------------

    [condition]

    --- sub event

    --- sub event

    ----------------------

    (these vents would handle the "flat" sides of your sprite collision polygon)

    [sprite is overlapping terrain at offset.x +1] (or x-1 if moving left)

    --- Set Sprite.DirectionVariable to "up"

    [sprite is overlapping terrain at offset.y +1]

    --- Set Sprite.DirectionVariable to "right" (or left)

    [sprite is overlapping terrain at offset.x -1]

    --- Set Sprite.DirectionVariable to "down"

    (Diagonals would be a little trickier)

    [sprite is overlapping terrain at offset.x+1 AND offest.y+1] (upper left corner of your terrain object)

    --- Set Sprite.DirectionVariable to "right" (if moving RIGHT, or set to DOWN here if moving LEFT - this is what I meant by it being a bit trickier with multiple directions)

    [sprite is overlapping terrain at offset.x-1 AND offest.y+1] (upper right corner)

    --- Set Sprite.DirectionVariable to "down" (if moving RIGHT, or set to LEFT here if moving LEFT)

    (Then finally the movement itself)

    [sprite.DirectionVariable = "up"]

    --- Move sprite and angle 270 at speed X (bullet behaviour - customer movement - however you're moving them)

    [sprite.DirectionVariable = "right"]

    --- Move sprite and angle 0 at speed X

    [sprite.DirectionVariable = "down"]

    --- Move sprite and angle 90 at speed X

    [sprite.DirectionVariable = "left"]

    --- Move sprite and angle 180 at speed X

    I hope that made sense. I can't make an example right now - but hopefully that helps a little?

    ~Sol

  • Will they always be traveling to the right or will they also be going left sometimes as well?

    I have an idea how to make it work - and should even work with terrain that's moving up or down, but implementation will be a bit different depending which way the sprites are moving. If always to the right it will be a bit easier, but if they need to go both ways it will be a little more tricky.

    Basically you will need an instance variable for each sprite, let's call it "direction". You will then need to set this instance variable to either "up" "down" "left" or "right" (or 1,2,3 or 4) using conditions - then set the movement in the desired direction based on the variable value. You will need a second variable for which *general* direction it's heading (left or right) if the sprites can move both ways. This second variable will act as a secondary condition check.

    Pseudo code:

    ----------------------

    [condition]

    --- sub event

    --- sub event

    ----------------------

    (these vents would handle the "flat" sides of your sprite collision polygon)

    [sprite is overlapping terrain at offset.x +1] (or x-1 if moving left)

    --- Set Sprite.DirectionVariable to "up"

    [sprite is overlapping terrain at offset.y +1]

    --- Set Sprite.DirectionVariable to "right" (or left)

    [sprite is overlapping terrain at offset.x -1]

    --- Set Sprite.DirectionVariable to "down"

    (Diagonals would be a little trickier)

    [sprite is overlapping terrain at offset.x+1 AND offest.y+1] (upper left corner of your terrain object)

    --- Set Sprite.DirectionVariable to "right" (if moving RIGHT, or set to DOWN here if moving LEFT - this is what I meant by it being a bit trickier with multiple directions)

    [sprite is overlapping terrain at offset.x-1 AND offest.y+1] (upper right corner)

    --- Set Sprite.DirectionVariable to "down" (if moving RIGHT, or set to LEFT here if moving LEFT)

    (Then finally the movement itself)

    [sprite.DirectionVariable = "up"]

    --- Move sprite and angle 270 at speed X (bullet behaviour - customer movement - however you're moving them)

    [sprite.DirectionVariable = "right"]

    --- Move sprite and angle 0 at speed X

    [sprite.DirectionVariable = "down"]

    --- Move sprite and angle 90 at speed X

    [sprite.DirectionVariable = "left"]

    --- Move sprite and angle 180 at speed X

    I hope that made sense. I can't make an example right now - but hopefully that helps a little?

    ~Sol

    @SoldjahBoy, thank you for the text examples but I'm still quite confused on how to go about implementing this. Can you please provide a example? I'm not too good with working with surfaces currently and things on them but I'm really interested in the movement and terrain that the sprites traverse on.

    Again, thank you for taking your time to assist me.

  • Yeah I'll see if I can make an example of this a little later today when I get some time. I have a few things on today, but later on I should be able to throw something together

    ~Sol

  • Yeah I'll see if I can make an example of this a little later today when I get some time. I have a few things on today, but later on I should be able to throw something together

    ~Sol

    Hey there,

    Any luck with an example?

  • Hi Usman, sorry I have been super busy with work. I will make something for you as soon as possible, or I will at least try. I'm not 100% sure my idea will work but I think it should.

    *EDIT*

    Did you need the sprites to travel left AND right or just one direction only?

    ~Sol

  • Hi Usman, sorry I have been super busy with work. I will make something for you as soon as possible, or I will at least try. I'm not 100% sure my idea will work but I think it should.

    *EDIT*

    Did you need the sprites to travel left AND right or just one direction only?

    ~Sol

    Left and Right.

    Thanks for your help, even with being super busy!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So I finally got some time....

    It was a little easier than I explained in my example. Hopefully this capx makes sense. Please note it's not "perfect" because of my sloppy placement of objects, and things aren't power of two in size. If you make your sprites better than I did, it should line up nicely. It may also freak out if you try to go too fast with the bullet speed... so you may need to mess around with the offset amounts (use 2px instead of 1) if you're making things go super fast.

    Hope this helps - DOWNLOAD

    *EDIT*

    Just added some vertical sine behaviour to one of the terrain blocks to see how it would go - seems to work pretty good

    ~Sol

  • SoldjahBoy, Thank you!

    This is amazing, this is exactly what I had imagined. I will definitely play with this and see how far I can take it.

    Thanks again!

  • No problem, I'm glad it's how you wanted it

    ~Sol

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