How to temporarily disable collision?

Omniso

  • Posts: 192
Is there a way to disable the collision of an actor (with a collision box) at run-time without:
1. Creating a fake animation and removing its collision box then having to switch to said animation and back over and over to simulate this.
2. Creating an entirely different actor with the same appearance but no collision box and switch out the current actor back and forth.

If it helps, the reason behind asking this question is that I've created a laser penetrates through and damages enemies. Due to rapid collision and the fact that this laser does not dissipate until a few seconds, this results in enemies being hit around 427 times, which makes it extremely difficult to balance and control its total damage. I'm trying to lower the amount of times an enemy actually collides with this laser and takes damage (while still in it) without having to do something that disrupts the current animation of the laser or do something that requires me to create a whole new actor on the scene for a problem that deals with just 1.

« Last Edit: June 17, 2018, 01:38:46 pm by Omniso »

squeeb

  • Posts: 1617
Boolean..  in the when hit code you are already using
If is hit is false...
Set is hit to true
Damage -1
Do after n seconds
Set  is hit to false


However.. id love to have an answer to your question!

Omniso

  • Posts: 192
I already have that exact same snippet of code (minus the damage -  1, and that [Do after x seconds] is 0.005) but it's used to prevent turrets, who's primary method of attack are projectiles, from dealing double or even triple damage if their projectile ends up hitting a specific spot that collides with more than 1 polygon that makes up the actor's collision shape or explodes upon contact. While this could work for turrets that fire lasers, it would end up creating scenarios where an enemy would be immune to damage from other sources while being attacked by turrets of this type, since I would have to raise the interval far higher than 0.005 to achieve my goal.

letmethink

  • *
  • Posts: 2545
What you could do is use these blocks to change the group of the collision shapes to something the bullets won't collide with and change them back after a certain time
~Letmethink

squeeb

  • Posts: 1617
What you could do is use these blocks to change the group of the collision shapes to something the bullets won't collide with and change them back after a certain time
Wait... this works even if you don't create the collisions with code?  And use the ones we draw in stencyl?

Omniso

  • Posts: 192
Help me understand this block. I tried it on enemy ships and changed their collision group  to Doodad upon them colliding with the laser actor, preventing anymore collisions after the first hit. Then, I decided to see if I could repeatedly loop between the group [Doodad] and the group [Ally Projectile] for the laser actor itself to reduce the amount of hits. It failed, but I noticed a couple things. . .

Image 1: I created an integer named X with a default value of 0 and placed this into the laser actor's code. The laser actor has only 1 collision box (a really long rectangle) . If I understand this correctly, this should print  "1", but it ended up printing "0"  (during the actual laser animation) which told me that the laser somehow has 0 collision boxes, and yet stencyl's actor collision tab is telling me otherwise.

Image 2: I realized that perhaps this must have been due to the fact that the laser has two seperate animations, a charging animation (a tiny glowing sphere with no collision which is the default animation) and the actual laser animation itself. I set the laser animation to be the default animation and the blocks worked (X was also = to 1 as expected when printed). Then I tried running the code below. The laser's group was changed to [Doodad] and did not collide, then 2.5 seconds later it was changed to [Ally projectile] and dealt damage (collided), then after 5 seconds it stayed apart of [Ally Projectile]. The reason I used [After X seconds] was because [Updating] and [Every X seconds] loops did not change anything no matter how I used the blocks, even as the way you showed in the image.

Note: Another thing is that this block did not work PERIOD after the laser's animation was switched from charging, and then to laser again, returning to its original group no matter what I do.

What am I doing wrong?

What are the limitations of this block?


« Last Edit: June 17, 2018, 04:04:39 pm by Omniso »

letmethink

  • *
  • Posts: 2545
What you could do is use these blocks to change the group of the collision shapes to something the bullets won't collide with and change them back after a certain time
Wait... this works even if you don't create the collisions with code?  And use the ones we draw in stencyl?
I think so...
~Letmethink

Luyren

  • *
  • Posts: 2812
If it helps, the reason behind asking this question is that I've created a laser penetrates through and damages enemies. Due to rapid collision and the fact that this laser does not dissipate until a few seconds, this results in enemies being hit around 427 times, which makes it extremely difficult to balance and control its total damage. I'm trying to lower the amount of times an enemy actually collides with this laser and takes damage (while still in it) without having to do something that disrupts the current animation of the laser or do something that requires me to create a whole new actor on the scene for a problem that deals with just 1.
One suggestion is to have the enemies be invulnerable for a short time after taking damage. Another is to add the collided actors to a list, and only damage them if they are not on said list. Both cases each enemy will only be damaged once per laser.

Third suggestion is do the same with the list, and in an always event count up a timer in another list for each actor hit. When a timer is greater than a specified value (invulnerability time for each actor), remove the actor with the same index in the list. So if the laser hits 3 actors, they will be added to a list in indexes 0, 1 and 2. Another list will increment numbers in indexes 0, 1 and 2 by 0.01 each frame. If the invulnerability time is 0.3 for example, once a timer reaches 0.3, remove the item in that index from both lists. Convoluted in writting, but this accounts for enemies being hit at different times.

Last option is to just make the laser damage less than one, and actually account for the 427 hits (enemies will receive more damage the longer they are inside the laser). Values such as 0.1, or even 0.01 might work depending on the damage scale of your game.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.