Q: Spawn object and collision

0 favourites
  • 10 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hello all,

    This is my first post here, just started using consctruct. Im trying to make objects spawn but still check for collision.

    I seem to get everything working except the spawn collision.

    Example:

    So i have for instance a rock with solid and collision enabled.

    And every 10seconds this rock spawns a new rock.

    The rock is spawned on a image point to the right of the original rock outside of the collision area.

    It is then given a new set position to a random spot Random(-20,20) away from this spot.

    The trouble is that each rock does this and the rocks start to randomly overlap.

    So i do a check for collision after the move and if it has collision it moves again. However this is verry ineffective because say i do it with Rock{1} (so i only remove the 2e rock of the collision) i see the rocks moving around on the screen to slowly form a non overlaping pattern, but everything jumps and does things... i dont really want that.

    What i would have liked is calling Move(true) or spawn(true) or something similar to explain to the spawn or move function that it needs adhere the collision and move or spawn to a new spot but adhere to collision (perhaps do a collision check before moving and getting new coords if the collision is true).

    Now i did manage to get this working someway or another (but not like i want it) by adding physics and not setting the position of the rocks but by actually moving them a giving amount of px/pt in a random(0/360) angle. This will make sure i get 0 overlap however everything ofcourse moves abit and its also extremely slow if i for instance generate 10000 rocks...

    So thats a whole bunch of string:), i hope its clear, if not i can post a file here tonight to show what i mean. However perhaps somebody understood what i want and knows a easy way to do this.

    Regards,

    Jasper

  • Not 100% sure of your requirements,ie are the rocks an even size?,does the width change if they are animated,is there a max or min gap size?...but will try to help

    Maybe try an invisable sprite,that is placed invisably into position first,then once seated with no overlap,create your rock at the invisable sprites position,then destroy your invisable sprite...that may work...

  • To keep it easy i kept the blocks 1size, not animated and there is no gap. The only requirement is that the colission EQ false

    What you sugested i tried without the invisible ;). I made a rockproxy, put that in place, did a check if there was anything there then replaced it, all until it found some spot without a colission. Problem is i made it visible so the proxys where bouncing over the place. It would offcourse (duh) work better to just hide it hehe. Thanks for the tip, on that note i can just do a rock.spawn and have the spawn be invisible until it finds a spot. Nice! Il try it tonight but pretty sure if it performs that it will do what i want. :D Sometimes its just so easy... :) il let you know how it went tonight :)

    Thanks Pixel!

  • Right took a bit longer then i had hoped but here is my reply :)

    It works... sort of.. I dont know why but even with a hidden proxy size equal to the rock the rocks sometimes overlap. Its not always, and 90% of the time it works but for somereason there are exceptions.

    i will keep working on it, if i find i cant get it to work atall il make a mokup quickly and post that here, perhaps im implementing something wrong :)

    Thanks again for the help. Back to my rocks :)

  • Sounds like your between a rock and a hard place...<groan>

    Not sure why that is...few things to cover...are the rocks destroyed on start of layout to ensure that only the sprites you have created are on the layout?...have you checked your image points are central?....are you using pixel rounding?....what behaviours do you have on the rocks...

  • aha now we are getting somewhere, on start of layout i need to remove things? even if i dont see stuff there can be something leftover? And i have 1 central image point and one off to the right, outside the bounding box. No pixel rounding. Rocks are solid nothing else.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes,if your objects do not have destroy on startup behaviour....they will be in the position they are in on the editor....as far as construct knows you may want them there....if they are bound to layout they will be thrown into your active layout during runtime...sounds like your image point may be the problem though....

    keep me posted...

  • hmm i tried to remove the image point that was outside the collision zone but i dont see alot of change :) Il try another way in a min then im off for this evening.

    If this doesnt work il make that mockup tommorow and i'l find a way to link it here.

  • Ok i found the answer... didnt plan on it but i got stuck behind the pc a bit longer :P

    So what i did was, add 8movement to the rocks and bam it works. The new rocks move to a spot close to the old one and everything works as i want it.

    Now i just need to figger out how big the impact is from using 8movement on so many things, and why does it work with that on? Is it because they are now allowed movement?

    Ow well, thanks for the help :) and if u can answer some of the other questions that would be awesome ;) Otherwise i will keep experimenting.

  • bit confused why 8 direction would help...

    I would be guessing a large performance hit on that though...it could be that 8 direction does not plot between pixels...so,if you tried pixel rounding that may sort it without 8 direction....????..<scratches head>

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