Physics in an infinite sidescroller

0 favourites
  • 8 posts
From the Asset Store
59 unique spaceships created in pixel art style within 48 x 48 pixels. Great for creating side scroller shooter games.
  • Hi everyone,

    I am currently trying to do a simple side scroller in an infinite level by scrolling the items through the screen and respawning them on the right. The player basically only moves up and down. This seems a lot harder than I thought. FYI: Im a rather experienced programmer (mostly not in gaming) and new to Construct2. Now sidescrolling is a pretty simple thing, or so I thought, thus I am rather disappointed on how difficult it proves to be. The way I tried it, it breaks some profound assumptions of the physics behaviour, and I am very much interested to hear what others have to say to my current approach:

    I have solid physics objects, some immovable ones (ground+platforms) and other movable ones (player sprite+items). Whenever the player "moves", all non-player objects move to the left while the player remains stationary in X. I just used set object.x = object.x-velocityX for all of them. This "simple" position change of movable physics objects breaks the physics behaviour completely, they wobble around and motion after collision is completely wild. So instead of assigning the items' x positions I now disable the items' physics until a collision occurs, so they are glued to the platforms and bumped away on collision by physics.

    This looks reasonably well, but I face the next problem: When the items are bumped away and remain within the view, they should come to rest on the ground or a platform, and then of course move to the left again if the player continues to move. Now when they come to rest on a platform (solid and immovable) and the platform is moved away to the left due to the player moving forward, the items remain floating in mid-air. Probably the physics engine (rightfully) assumes that collisions need not be updated for an immovable object. So I triggered a "refresh" by enabling and disabling the physics behaviour of the platforms. You really shouldnt have to do that, should you? And of course, still, the items do not move with the platform to the left.

    Of course these are just hacks around the basic problem which is: How can I tell the physics engine that its "world" is moving to the left? Or cant I use the physics behaviour at all? I did some other experiments, such as using the physics properties to move the items instead of setting x positions directly, but without much success.

    Best regards,

    Marc

  • What if you used two kind of objects (that look exactly the same). The one with physics and one with no physics behaviour and switch between them when needed. Maybe the spawned one another depending on the situation. Probably a bit clumsy idea, but if works then great. I used in my game a two sprites. One being physical and one being just a sprite without behaviour (except bullet to "the sky"). The later was the same sprite with added in photoshop a balloon, from which the guy was hanging. The balloon has a bullet behaviour etc. and when popped I destroyed the ball after it had spawned particles and same time that animation sprite is destroyed also and it spawns the main character to it´s relevant image point.

    Maybe those things coming from right to left could have a bullet behaviour and once colliding they turn into physics

    I am not sure if I understood your problem correctly but this kind of "solution"came to my mind.

    edit. It seems that the problem is with immobile to yes. Does it has to be that way? What if it has gravity=0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi there,

    thanks for the idea, I guess basically Im doing that when I disable/enable the physics behaviour on the item. As to the gravity idea: The manual says that "gravity applies to the whole "world". If you set gravity to 0 on one object, gravity is turned off for all objects", which wouldnt help me - is there an other way to do it?

    Edit: When using physics enable/disable I find that collision between items again makes the collisions pretty wild, so that isnt working well unfortunately.

  • I haven´t tried it but somewhere in forum is said that one can simulate gravity by giving each sprite an individual force (downwards) and setting gravity to 0. But not sure how well it works.

  • Is this what we talk about ?

    https://drive.google.com/open?id=0B1SSu ... Wg3eVlrRFk

    (so much easyer if you provide that capx)

  • I cant open that project unfortunately, its a newer version (although I have 227 which is "latest stable")?

  • Reduced test-version to demonstrate the problem: https://www.dropbox.com/s/8lvi4avjevxw1 ... .capx?dl=0

    Some of the variants I tested:

    Variant 1a: platforms not immovable, modified by set x, items not modified

    -> Problem: items "slide" along platforms

    Variant 2: platforms not immovable, modified by set x, items modified by set x

    -> Problem: breaks physics

    Variant 3: platforms immovable, modified by set x,

    items modified by set x with physics disabled, enabled on collision

    -> Problem: best so far, but collision among items are unstable, "sleep" state is not enough to detect rested items

    Thanks for any hints,

    Marc

  • No more hints? Is side scrolling so bad?

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