Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Endless falling

Discussion in '2D' started by tester0126, Nov 22, 2019.

  1. tester0126

    tester0126

    Joined:
    Nov 17, 2019
    Posts:
    2
    Hi guys,

    is there any way how to do "vertical endless falling" of some object? Let say that in the background will some kind of skyscraper and when object fall down, background will automatically move down and repete his own layer.

    Thx for any help, have a nice day.
     
  2. blu3drag0n

    blu3drag0n

    Joined:
    Nov 9, 2018
    Posts:
    94
    You would simulate the endlessness by chaning the parameters around rather than trying to really move something endless into one direction.
    Means that if you want some sort of endless-fall-down-effect you would manipulate the sprite of the seemingly falling down object (e.g. player) the way that it looks like its falling, but you actually keep it in the same postion for the whole time and then you would spawn objects perfectly below the bottom camera border and move them upwards until they (for example) been hit by the player (collecting coins, making damage or triggered whatever it could on collision) and if they left the upper camera border you would just despawn them.
    Then you would have some sort of animating background that further improves the imagination of endlessly falling.

    Do you know what i mean ?
    You actually would "never" move everything endlessly in one direction over just easily faking the effect which is generated when doing as i described.
    Furthermore it's much easier to controle all the necessary objects in the way I described them and troublshoot and test stuff against an approach where you would have your objects somewhere in the middle of nowhere.
     
    tester0126 likes this.
  3. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    Let's say you're doing a background. Apply Rigidbody2D to it and make it a prefab. You can also add a collider on it as well. You want to spawn your prefab through Instantiation. The gravity will make the image fall. Set up a collider to when the background image collider hits, it spawns another background image that falls. Be sureto destroy the images when they hit the collider, something like Destroy(bgImage, 1f);

    This way your old image gives the new background image enough time to get caught up so it makes a smooth transition. You may require timing on the spawns so your background has an unnoticeable tiled effect.

    Edit:

    Now if you're just falling in open space and you want something like a wind effect or stars, you can simply use a particle emitter. This would be very easy.
     
    tester0126 likes this.
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @tester0126

    What @blu3drag0n said is probably the best way, doing it like most infinite/endless runners do their treadmill backgrounds.

    Another common way is to do this with UV animation, by animating material texture offset, but this usually works best when you only have one texture that repeats endlessly.
     
    tester0126 likes this.
  5. tester0126

    tester0126

    Joined:
    Nov 17, 2019
    Posts:
    2
    Hi guys,

    many thanks for your help, really appreciate it! That's exactly what we need :)
    Have a nice day and once again - thanks.
     
    MisterSkitz likes this.