How do you get a character to die when they touch an object

i’m not that good at coding but i try

You’ll have A LOT of options! I’ll try to list as many as a I could… but just swap the word, input1 with the name of the player, and input2 with the thing that’ll kill the player.

  • Use the .remove function (which I won’t recommend since it just makes the character disappear). Plug this code into the update script of any object:

if(input1.hitTest(input2)){
input1.remove();
}

-If u don’t have a lot of frames in the player, you could have him/her play the frames, and then onto the next frame, you could animate how you’d like the player to die (ex: jump out of the screen, fade away, zoom in or out until gone, gets eaten by a monster, etc.), and remember, instead of just playing the frames, you could use the gotoAndPlay(/frameNumber/) function to make the player go to the exact frame that ur animation would start. Here’s how it could go coding wise:

if(input1.hitTest(input2)){
input1.play();
}

Have the player disappear slowly (fade away) by using the following code:

if(input1.hitTest(input2)){
onEvent(‘update’, function () {
input1.opacity-=.03;
});
}

Or just move the whole timeline of the actual project

if(input1.hitTest(input2)){
gotoNextFrame();
}

Let me know if that’s not what u were looking for, and if you’ll need any help with the following code, just let me know, I hope I made them simple.

ok so what i need is when you touch somthing you move to the nest frame but i need a backgoud

making background won’t be hard. Make a new layer, have it be below the first layer (so it stays in the background), lock the main layer (so it doesn’t annoy u), and start painting, or insert a file image in the backgrounds layer. U could have an abstract background,colorful, or theme based background -it really depends on the project and ur creative view of it

(was that what u meant by “i need a background,” otherwise let me know)

i thot the background was affecting how the project worked so is trying to find a way around
at this point it’s just giving me the screen that says this code does not work.

I hate when that happens

I might know what’s the problem, but can u send me a picture of the code that u plugged in with the red error? That’ll be pretty helpful :slight_smile:

put this code in the character’s update script:

replace that with the killing object’s name
replace Y with the starting frame, the first frame of the actual gameplay, or a gameover frame.

sadly screenshots don’t work on my computer

thanks let me see if works

not working ;(

Here, this might help:
one way to make a player die.wick (136.9 KB)
html version of the wick file is here.html (2.2 MB)

The code is put in the objects that kills the player, the red rotation star. Just keep going right and you’ll find it and you could see how it works. Let me know if this helps

k thanks u

1 Like

send me the wick file, I’ll try to fix it.

k :) THX MAN

Uploading: My Project (1).html…

WORKED yay me happy

what ? what are you saying?