Step 4
Making the player character temporarily invincible after it crashes
This will be the final part we'll add to the player character script to deal with crashing. To make the player invincible and ghostly for one second, we'll need these blocks:
set alpha of myself to 0.5 (from Looks) set any side collisions to false (from Physics) 1000 milliseconds have passed (from Control) First, grab the "set alpha of myself" block from Looks. Place this block directly after the "set number lives to number lives - 1" block as shown. Change the number to 0.5 (this will make it half transparent, with alpha 1 being fully visible, and alpha 0 being fully transparent).
Then grab the "set any side collisions" block from Physics, and place this block under the previous block, and set it to false. We're using this block to prevent collisions without disabling physics, since we still want gravity and velocity.
We've made it so the player will become invincible and transparent -- but we need it to switch back to normal after a second. So grab the "100 milliseconds have passed" block from Control, and drag it underneath the last block we placed. This block is a time delay block: it makes anything inside it happen only once a certain amount of time has elapsed. Change the number from 100 to 1000 (since 1000 milliseconds = 1 second).
Duplicate the "set alpha" block and "set any side collisions" block, and drag them inside the time delay block. On the duplicated blocks, change "set alpha" to 1, and change "set any side collisions" to true. Now after a second the player will no longer be transparent and invincible.
Finally, we need to make sure the player retains velocity after crashing into something. Grab another "Set velocity x" block from Physics, set it to 100, and put it in the Constantly event.
In the next tutorial, we'll display the lives on screen as text: HUD interface: making text and objects follow the camera