Discuss Scratch

kazim678
Scratcher
26 posts

how do i make it so the player doesnt lose health for 1 second after getting hit

i made it so that health went down by -1 when touching boss and theres a total of 3 health. but the health rapidly goes down so that you lose all 3 health by colliding with the boss once. I want to make it so that the player is invincible for a second so they can get away
Jlerpy
Scratcher
1000+ posts

how do i make it so the player doesnt lose health for 1 second after getting hit

If that's the only source of damage, you could just add a wait 1 second to the end of the code for losing health.

If there are other sources, you can use a variable - let's call it Invulnerable - then get your damage code to check it's No before you apply the damage, and then to set Invulnerable to Yes.

Elsewhere (probably in your player or health sprite), put in:

forever
if <[Invulnerable] = [Yes]> then
wait (1) secs
set [Invulnerable v] to [No]
end
end

I think that should do the trick.
Oumuamua
Scratcher
1000+ posts

how do i make it so the player doesnt lose health for 1 second after getting hit

I´ve seen some games where when the player receives damage it moves some steps back and the enemy freezes by one or two seconds.
Jlerpy
Scratcher
1000+ posts

how do i make it so the player doesnt lose health for 1 second after getting hit

Knockback is also a good idea.
kazim678
Scratcher
26 posts

how do i make it so the player doesnt lose health for 1 second after getting hit

couldnt get it to work this is my project : https://scratch.mit.edu/projects/752082378/
Yusei-Fudo
Scratcher
1000+ posts

how do i make it so the player doesnt lose health for 1 second after getting hit

This is your original Script:


What I added:
AksharPremnath
Scratcher
500+ posts

how do i make it so the player doesnt lose health for 1 second after getting hit

kazim678 wrote:

couldnt get it to work this is my project : https://scratch.mit.edu/projects/752082378/

where in the project is the defective script?
kazim678
Scratcher
26 posts

how do i make it so the player doesnt lose health for 1 second after getting hit

Yusei-Fudo wrote:

This is your original Script:

What I added:


it worked bro youre a genius

Last edited by kazim678 (Oct. 31, 2022 23:59:45)

Powered by DjangoBB