Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
How to make something invulnerable for a few seconds
  • Hi there. I'm building a sidescroler based on the HH tutorial. After a collision I would like to set the player invulnerable for maybe 3 seconds, so any collisions in this time won't reduce his health. I implemented a condition in the collision rule only to take place, if the player is in the flying state, not in a hurt state. Sadly this rule seems to "store" a collision that takes place in the hurt state and it subtracts the healthpoints right after the player goes back from hurt to the flying state. So it creates some wired kind of a delayed hit mechanism. Any ideas how I can do it right?
  • 9 Comments sorted by
  • @Cavaron, try to disable the collision state of the HH. Then place a timer that has a 3 second action on it that enables the collision state.

    1. Set a global for your collision state. CollisionPossible=1
    2. When the HH is hit change your property CollsionPossible=0.
    3. If the CollisionPossible=0 then start your 3 second timer, at the end of the 3 second timer set CollisionPossible=1.

    Hope this works for you.
  • @Carlton:
    Thanks again for you reply :) I'm not sure if I got the details of your suggestion or how it differs from my approach, besides of using a global variable as collision rule instead of an entity state.
    I tried it anyway with the same result. As soon as the timer runs out, collissions which happened while in "invulnerable" or "hurt" state or while the CollsionPossible variable was 0, will count as soon as it changes back to Flying or 1.
  • @Cavaron, the collision condition doesn't store a collision. If you want to implement a delay to prevent collisions from triggering an action for 3 seconds and you are using the State Machine then you should simply be able to add to conditions. One to check the "currentState" property on the State Machine component and the other to check for a collision event. Make sure condition type is set to "ALL" so that all conditions have to be true in order for the attached actions to fire. Make sure to keep the player in the "hurt" state or a separate "vulnerable" state for 3 seconds before transitioning back to the "flying" state. That should do the trick.
  • @Lavon: Thanks for your answer. I did it like this in the first place, but there seems to be something wrong. I tried to recreate the error in the HH game I did, but there it works without any problems. So the error must be somewhere in my logics... tripple checked names and states so far, all the rules say ALL instead of ANY. The Animations from the Hurt state play as they should (so the state gets activated) but collisions still take effect after the timer for changing the state from Hurt back to Flying runs out. Well, at least I'm good in creating strange errors ;) Makes me crazy tho...

    Any chance you take a look at this when I go "Pro Plan" later? Does this fall under priority support?
  • Strange thing - instead of writing a collision rule both in the Player-Entity and the Obstacle-Entity to reduce each ones health, I decided to let the Obstacle-Entity do the whole job. I simply copied the "Player state to hurt" trigger from the collision-rule of the Player-Entity over to the collision-rule oft the Obstacle-Entity. It just works now how it should. Can't stop wondering about that... but I'm happy now :)
  • @Cavaron, can you zip up and send in your project that has the error? I would like to take a look and make sure it is not a bug in GameBuilder Studio. Send via 
  • @Lavon, sorry - don't have a backup from the project at that state. I tried to reproduce the error without any luck. I can just assume that I really overlooked an error or that by some strange incident an error was created in the code - I accidentally entered the console several times, who knows. I guess the problem would have disappeared if I had deleted the hole hurt-logic and did it again.
  • @Cavaron OK so the collision logic is working as expected now?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion