How do I lock objects within circular boundary

0 favourites
  • 8 posts
From the Asset Store
Is a circular loading screen with code ready to use. No Animation.
  • here is what i want to do but don't know how to:

    I created sprite that is just a circle. I only care about its border so both inside and outside of the circle is transparent.

    I added the sprite, and in "edit image" i clicked set collision polygon and later added "solid' behavior to it.

    Now i spawn smaller boxes with bullet behavior that bounce off of solid objects.

    I create them inside the box and set their angle to arbitrary degree.

    At this point, they do not move and i am guessing this is because the collision polygon is set to all areas inside the circle, not just borders. What is the most efficient way of setting up a circular wall so that other objects can move freely inside it?

    Thanks

  • One way that I just tested and works with some tweaking... Make two circle sprites, one larger than other slightly so when they overlap you get your "ring" when inner sprite color is set to backgrounds. You can make circle sprites in Construct2 sprite editor by using paint brush and setting its brush size to 260ish for large and 250ish for inner.

    Click the crop tool to remove excess from around edges and then edit collision polygons by right clicking circle and selecting "guess shape", tweak and add points as needed.

    Once you have your two circles arrange them on layout so your ring is showing.

    Use System Every X Seconds and set to whatever you like... I used 0.1 and it worked good but if you want it faster than use 0.0#. You could use every tick... but why.

    I made a sub-condition off the Every-X-Second that does a Sprite (your bullet object) is overlapping inner sprite and then right click and choose Invert.

    The action is Sprite (bullet object) bounce off outer sprite. You would also put your angle stuff here to keep it angled back inside.

    It worked as intended but would need some tweaking to be perfect.

    Another method since its a circle and the distance from center will always be the same, would be to get the center X,Y coordinate and then have the bullet object check its distance from center (var) with a center.X,center.Y, bullet.X,bullet.Y action and then react if its greater than your "ring" distance from center.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • couple of ideas

    first is with maths - have a look at viewtopic.php?f=147&t=69754&p=590475&hilit=limit+circle#p590475 as a starting point

    second is make several graphics that would make up the outside of a circle and use these

    ( https://goo.gl/wsnUZV )

  • thank you both, using distance to detect border line is really interesting and i might go that route but i am curious is there a way to invert collision polygon? that would be most neat and ideal solution.

    thanks

  • not that I know of - hope I am wrong (again)

  • You can make a shape that looks like an "inverted" polygon but I don't recommend it, it's time consuming to do and goes against C2 prinsiple of not using more than 8 vertices per collision polygon.

    Here is a capx that uses the "inverted" polygon method, multiple sprites for detecting collisions, and the distance method. The distance is by far the most efficient way to do it. You'll have to find a clever way to fake the bouncing at random directions however.

    https://www.dropbox.com/s/snj05xr3ic73t ... .capx?dl=0

  • Can be made in an easier way, but..

    ..just having some fun

  • LittleStain , wow, I'll have to recheck the definition of the word "easier"! Nice job !

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