How do I - Infinite Diagonal Scrolling (For endless runner)

0 favourites
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • EDIT: CAPX file included.

    Hi All,

    Very new to Construct 2 and I already love it.

    I am trying to make an infinite running game where I randomly line up different poles(or road) which my hero has to walk on. The poles are not in straight platforms but diagonal. Start from Top right scrolling towards bottom left. Here is a sample image I created to show what I am trying to achieve.

    [attachment=0:zgnpf9wz][/attachment:zgnpf9wz]

    [attachment=2:zgnpf9wz][/attachment:zgnpf9wz]

    At every Tick, I am incrementing the Pole objects' X,Y but (-1,1). Also tried at Layout Start added bullet motion to -225 deg.

    As the poles move downwards, I am creating new poles at the top. This is where the problem started.

    1) I am not able to properly identify where to place the newly created Pole from. How do I get the Position of the Last created Pole, so that I can "attach" the new pole to it?

    2) I then noticed my Pole platform started drifting to much towards the left, like this:

    [attachment=1:zgnpf9wz][/attachment:zgnpf9wz]

    3) I managed to identify the last created Pole using an Instance boolean variable called ISLAST. Using this I trapped the X and Y and use it to position the newly created object. But I am hoping there is a better way of doing it.

    I primarily need help with the drifting Platform/Pole. Any help will be greatly appreciated!

    Thanks,

    Sam

  • I don't think you need the ID of the last placed pole at all. In most infinite scrollers you don't even need to scroll - it's an illusion.

    Is the character always "climbing" up and to the right, in the same angle, or are there sections where the player can go down and to the right, or horizontally to the right?

  • Hey Fimbul

    So glad someone responded.. Thanks a lot.

    I created an "invisible" wall to mark the point at which a new block should be created. Its kind of okay now. I was able to nearly able align the new objects to the currently colliding block.

    To solve the drifting issue I used the "Custom Movement" behavior and at every TICK telling the block to Accelerate toward certain X,Y(ie, Bottom left corner). For now its working fine except the initially created poles.

    But yes.. later on I would want my character to change directions too. In that case my "Accelerate toward X,Y logic wont work out. Is there a something that can handle the change in direction?

    Attached is the Capx file for your study.[attachment=0:zf5dxmoq][/attachment:zf5dxmoq]

  • Here's an example I put together. All in 13 events, so you could work this into a game even with the free edition. Also I was wrong, you apparently do need the last platform ID (unless you want more maths).

    Press "enter" to change the angle (but wait a few seconds before you do that)

    Scrolling is a bit bonkers but you should be able to fix it with some maths or creativity.

    Sorry for the scary math. It's probably possible to get rid of it all and replace it with something easy.

  • Thank you!! Looks like you saved this with the Beta. Downloading the new version now

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Fimbul You sir are a genius!!! I literally had tears in my eyes when I saw how much time and effort you took to comment every line with so much detail. Thank you so much!

    After all those math functions I realized I am far behind and need to do some serious reading.

    I will now try to integrate your awesome logic into mine. I had just one more question but I will ask that once I have your awesome logic on my game

  • Hi Fimbul

    I am back. .. I tried your code. It works great. . I had to make some changes in order to keep the images from rotating but keep the angle of scroll same. After I replaced your sprite with mine, I had to make some adjustments to the Y coordinate in order align them properly. But when I do that, the platform starts moving downwards at every interval.

    Here is the change I made to adjust the Y position for a new platform:

    [quote:zm1diu5b]

    Y= (Platform.Y)-sin(Platform.Angle)*(PlatformWidth/2)-sin(PlatformCreationAngle)*(PlatformWidth/2) + addY

    And this is how I intend to create my images (not final). As you can see they are isometric tiles, which I will be joining to create a chain to pipes connected.

    [attachment=0:zm1diu5b][/attachment:zm1diu5b]

    Now when I am walking on tile #1, I continue scrolling in the default angle (as in ur code). But when my character touches tile #3, I change scroll angle to the opposite direction. Of course the character will remain in center of the screen.

    The only problem I have right now is that the platform starts moving downwards when I add a Y value. Is there an mathematical way of handling this??

    Thanks again for your time and help!!

  • Ah, I understand now what you're trying to do. I was operating under the impression that this auto-runner of yours was a platformer, but it's an isometric game...

    Which is quite weird since your drawing on the original post showed a platformer-style auto-runner. Did you change the scope of your project? If so, this smells like feature creep, and you should probably revert to the original platformer design.

    However, if you still want to press on with the isometric gameplay, you're better off ditching the whole logic and starting over with a modified iso tiling engine (one that only draws the tiles you need), since your pipes are basically tiles. There should be some examples around in the forum.

    When creating new tiles, remember to push them to the bottom of the z-order, and use image points (as well as instance variables) to create attachment points for the newest pipes.

    You'll need to scroll all the tiles instead of the player, which will have to be done using basic trig (you can't rely on the layout editor to handle the scrolling for you).

    All in all, I recommend reverting to the original design.

  • Fimbul, only the graphics look like isometric but concept is still the same. Instead of rotating the platform, I want to use a curved platform to represent the change in direction. I drew an isometric diamond around the pipes to give you an idea of what ends need to join when a new tile is created.

    Your logic works perfectly, I was even able to randomly pick variously tiles and make a continuous path. The problem I am facing is when I try to adjust the height with the previous tile, the whole platform starts drifting downwards.

    And I am really sorry about the first images. I had no images ready and quickly made them on Paintbrush to give an idea of the problem I was facing. I should have taken an isometric character to show that he will be walking inside the pipe area

    Thanks again for your time and recommendation. I am sticking to your logic, just need help with managing the additional X, Y adjustments

    Most Importantly: If my game ever sees light of day.... I will give you all the credit for helping me

  • Fimbul, only the graphics look like isometric but concept is still the same. Instead of rotating the platform, I want to use a curved platform to represent the change in direction. I drew an isometric diamond around the pipes to give you an idea of what ends need to join when a new tile is created.

    I see. Well in that case you could draw a "connector" bend every time the direction changes.

    Your logic works perfectly, I was even able to randomly pick variously tiles and make a continuous path. The problem I am facing is when I try to adjust the height with the previous tile, the whole platform starts drifting downwards.

    Y= (Platform.Y)-sin(Platform.Angle)*(PlatformWidth/2)-sin(PlatformCreationAngle)*(PlatformWidth/2) + addY[/code:1qb3e2sa]
    
    

    That code is responsible for scrolling all platforms! Adding/subtracting a number means "add drift" in this context, whereas multiplying by a number means "change the speed". Your code adds to Y, which means it's going to drift downwards.

    Let's simplify the formula so that it becomes easier to see:

    Y=(Platform.Y)-sin(Platform.Angle)*(PlatformWidth/2)-sin(PlatformCreationAngle)*(PlatformWidth/2) + addY

    This looks suspiciously like:

    Y=Y+addY[/code:1qb3e2sa]
    
    What you need to do is:
    [ul][li]Pick only the instance you just created (the create-object action pre-picks the newest instance for you, but I don't know if it "un-picks" the other instances, you'll have to test)[/li]
    [li]Add/Subtract to it's Y position only once (preferrably at the moment of creation). You don't need any fancy formulas to it, just add directly to it's Y position.[/li]
    [li]I would avoid adjusting the X position, since that can cause seams to appear. The platforms will always be coming from the right, correct?[/li][/ul]
    
    
    

    Most Importantly: If my game ever sees light of day.... I will give you all the credit for helping me

    Don't worry about that man, just pay it forward.

  • What you need to do is:

    • Pick only the instance you just created (the create-object action pre-picks the newest instance for you, but I don't know if it "un-picks" the other instances, you'll have to test)
    • Add/Subtract to it's Y position only once (preferrably at the moment of creation). You don't need any fancy formulas to it, just add directly to it's Y position.
    • I would avoid adjusting the X position, since that can cause seams to appear. The platforms will always be coming from the right, correct?

    I am only adding the Y in the platform creation event. The scrolling code is still the same.. but I am now wondering if I have to deduct the additional Y at scroll.

    I also tried creating an extra Origin Point to define where the next tile should spawn, but this too resulted in drifting.

    Not sure how to proceed now

    Don't worry about that man, just pay it forward.

    Trust me I will

  • Post your capx again and I'll take a look.

  • Post your capx again and I'll take a look.

    Here you go... I am using variable "addY", set it to zero to see your default logic work. Value of 24 makes the tiles align.

    I am using "Direction" and "Ang" instance variables. Ang is used instead of the inbuilt "Angle" property (needed for scrolling)

    Let me know if any questions

  • Well I was somewhat wrong and somewhat right. Yes the downward motion is to be expected if you do it like that (like I said), but it's also what you want. The downward motion is desirable.

    It stems from the fact that once the engine places the first platform, it starts connecting them front-to-back, and since you're always correcting the newest platform (pushing it down), the newer platforms will accumulate the effect.

    How do you fix it? By making the platforms go "up" to offset the motion: Like the comments say, the engine is lacking scrolling. You need to add logic to keep the platforms (or the player) centered on the screen, and you cannot rely on the automatic centering provided by Construct 2 because your game is an infinite scroller, not a predefined level.

    There are many problems with using "tiles" in the way you're describing:

    • The player has a cyan "detector" sprite below him, and it relies on thin, rectangular platforms to work, otherwise it might detect two platforms simultaneously and not know which angle to pick. The thinner the platforms, the less this problem happens.
    • With fixed tile platforms, you can only bend the pipes in 90º increments.
    • With tile platforms, you can no longer use the platformer behavior to handle player movement, you'll have to come up with custom movement logic.
    • setting addY to 24 does not make the platforms align. 34 works better, but makes the tiles overlap. Also this only works for the initial angle, all other angles break. That's because addY depends on the angle, it can't be a fixed value.
    • Having isometric tiles make the whole connecting logic collapse, since when the engine tries to figure out where to attach the new platforms to the old ones, the maths give it the wrong answer, and things look jumbled.

    This is not to say that isometric tiles are impossible, it's just that they're very very hard to work with this engine, which is designed to support a platformer.

    If you do want to stick with tiles, I can help you a bit, but it involves starting over from scratch.

  • You are right about everything. This thing is getting tougher with every new idea. And Construct 2 seems to be very restrictive.

    Here is the game that inspired me to go with this style of representation. Its was made using Construct 2.

    (URL not allowed )

    youtu.be/m0lCsQQE4N8

    viewtopic.php?f=148&t=98236

    I dont want it to be so complex, with varying platform height. Just basic, pipes going Straight, Left, Right. Do you think its possible?

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