How do I lock objects within circular boundary

Get help using Construct 2

Post » Sat Oct 31, 2015 4:19 am

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
B
5
S
1
Posts: 32
Reputation: 439

Post » Sat Oct 31, 2015 7:42 am

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.
Last edited by chrisinfinger on Sat Oct 31, 2015 8:07 am, edited 1 time in total.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
70
S
19
G
8
Posts: 639
Reputation: 9,674

Post » Sat Oct 31, 2015 7:48 am

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 )
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sun Nov 01, 2015 2:39 am

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
B
5
S
1
Posts: 32
Reputation: 439

Post » Sun Nov 01, 2015 8:43 am

not that I know of - hope I am wrong (again)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sun Nov 01, 2015 1:12 pm

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
Last edited by eli0s on Sun Nov 01, 2015 3:00 pm, edited 1 time in total.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Sun Nov 01, 2015 2:16 pm

Can be made in an easier way, but..

..just having some fun
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Nov 02, 2015 10:59 am

@LittleStain , wow, I'll have to recheck the definition of the word "easier"! :D Nice job !
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests