Get Player actor invincible, flicker and be able to pass obstacles and enemies

adytt

  • Posts: 51
Hello to all,
Still in the process of trying to finish my first platform game and I need a bit of help regarding adding an "invincibility" behaviour to main main character.

Currently I have my Player actor aka Hero set up like this in term of animations
- walk (left + right) ; jump (left+right); shoot (left _ right); Hurt(left+right); Die (left+right); Dead (left +right); duck (left + right);

Once my Player gets hurt by an obstacle (ex. spikes) he gets trown a bit back and up in the air.

Inside my hurt behavior I would like to add a part to handle invicibility like this:
-After the Player takes damage, start to Flicker and become invincible for 3 sec. While invincibility is ON I would like the player to be able to pass through enemies and obstacles.

My problem is that I don't know how to make the Player be able to pass through enemies and obstacles (not register collisions) while invincibility is on.

Currently my Hero Character aka Player can collide with : Tiles, Enemies, Obstacles, Enemy Fire and Collectibles

I've searched the forum and found an option of using multiple collision boxes for the Player, yet I don't know which code blocks to use in order to switch to a collision box that is inside a group that won't collide with the Obstacles/Enemies/Enemies Fire group for example when the invicibility is ON.

I attach my Hurt Behaviour here in case one that can help needs to have a look and also to ask if there is a more optimized/elegant way to code it.



JeffreyDriver

  • Posts: 2262
You could have the invincibility as a separate animation that has it's own collision group.

Alternatively could could approach it from the other way and switch the collision shape of the spikes to a sensor briefly.

If you want to use the blocks under ACTOR > PROPERTIES > COLLISION SHAPES you need to create the collision shapes when the actor is created and assign them attributes.

adytt

  • Posts: 51
Hello Jeffrey and thank you very much for you kind reply.
Really appreciate your help.

So after trying to build the behaviour like in your second suggestion by using the sensor type collision for the obstacle (spike), I finally managed to get it done  and I attach it here so that maybe others can also get a benefit from it.
Still needs a bit of attention in order to synchronize the flickering timer with the invicibility time.

I would also like to learn how to build the behaviour  by using duplicate collision box/shape for the Player and change to the necessary collision shape once the damaged ocured.  I have looked under the ACTOR > PROPERTIES > COLLISION SHAPES, yet I don't find a block for switching to another collision shape. so if you have time can you please share a bit of PseudoCode or such to have a better understanding of this?

P.S
I have my main Actor Placed on the SCENE and not creating it by code when the scene Starts so I have to ask if this is a drawback while trying to use this manner.