Spawn sprite if there's space + Wall and weapon collision

0 favourites
  • 7 posts
From the Asset Store
Wall Pin Board is a hyper causal game developed for fun and inspired by YouTube video whose link is given in description
  • Hi, I have two problems.

    1) I need to check if there's sufficient free space for a sprite to spawn another object right next to it (horizontal, vertical and diagonal directions). So, if there's enough space and no existing sprite in that area, sprite will be spawned. If there is already a sprite in the immediate 64x64 pixel area (size of each sprite) next to the spawner sprite or there's not enough space for spawn in that direction in the layout, object cannot be spawned. Something like this: https://dl.dropboxusercontent.com/u/163 ... roblem.png

    Spawner sprite (also 64x64 px) should first try to spawn another sprite horizontally to its side (in its facing direction), then if that's not possibly try to spawn diagonally, then last vertically. I should mention game is not locked to a grid-based movement. How would I go about achieving this? I've been trying to solve this for two days now so any help would be greatly appreciated:)

    2) I have a sprite that's moving using platform behavior that I need to attach a weapon to. I can do this either by pinning it to the platform behavior sprite or setting the position of the weapon each tick. I don't want the weapon sprite to pass through walls, so I've given it a solid behavior. However, it still passes through the walls anyway and the solid behavior also creates another problem, preventing normal movement to the direction weapon is attached to. Here's an example capx:

    https://dl.dropboxusercontent.com/u/163 ... oblem.capx

    What would be the best/recommended way to fix this and have the weapon not affect the normal movement and also stay within the wall boundaries. I need a solution to have the platform sprite "respect" the collisions of the weapon and not be able to move any further in the direction weapon is about to overlap with a wall. Any ideas?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • adding physics to the sprite/base, so on spawn it will be bumped away from the other instance. (if you do this theres a whole lot of tweaking on physics rotation and linear damp)

    or

    you could have a condition, spawn checker at x,y if checker is overlapping sprite, checker set position to (checker x+64,checker y) if checker is overlapping sprite set position to (checker x-128 , checker y)

    have else conditions for each overlapping check, and spawn sprite at checker, then destroy checker. not sure how this will work for multiple instances though)

  • Aher0 Thanks, I tried having a checker sprite but I couldn't get it to work properly, for some reason it didn't register the obstacles and would just always spawn sprites. If there are any example capx of this sort of functionality to study that'd be great!

  • About your second problem:

    A good practice is to have a dummy invisible sprite with the platform behaviour and your main player sprite attached on to it.

    It's the invisible sprite that all collisions should be checked against and you can alter its size on runtime, depending on if the player has acquired the gun or not.

    https://dl.dropboxusercontent.com/u/14855413/c2/bbox.capx

    In the example above I made the invisible sprite semi-transparent so you can see what's happening. Press G to give your player a gun and you'll see the bounding box growing. Press H to destroy the gun and the bounding box shrinks back.

    NOTE: The enlargement of the dummy sprite depends on its origin point. You'll see that it is placed to the hard left, so that when the player changes direction you have to mirror that sprite too.

    EDIT:Forgot to mention that you can always have a different animation with the player holding the gun, as an easier alternative to the above.

    Which method you prefer depends on if your player has dozens of guns he can get or just a couple.

  • immortalx thanks, that might be a possible way to solve it, I've used invisible collision sprites before but didn't try this method for this test. Using different animations are not ideal in this case because there are multiple guns, but dynamically resizing the collision sprite size is interesting and might work. One thing that worries me is if the player sprite collision area needs to be more complex than a rectangle things might get funky upon resizing, but other than that it could fix the issue. Anyway, I'll check the capx and report back when I get home from work Thanks again!

  • Waltuo

    Look at this updated capx:

    https://dl.dropboxusercontent.com/u/14855413/c2/bbox2.capx

    I just added an animation frame to the dummy sprite, that switches depending on if you have the gun or not. I also scraped the re-sizing part.

    The second frame has a collision poly closer to what you want. If all your guns are about the same size, this should work.

  • immortalx Thanks! Needs more testing in game but so far the 2nd method seems to work great:)

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