ForumsProgramming ForumHittest with explanation?

13 4710
Midmenj
offline
Midmenj
216 posts
Nomad

I need to know a hittest that allows you when you fall off something you lose a life. That's it.

  • 13 Replies
Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

if(Object1.hitTest(Object2))
{

}

This only check if their borders are touching tough

Midmenj
offline
Midmenj
216 posts
Nomad

so i name each symbol object 1 and object 2?

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

That was just an example, you gotta use their instance names, not symbol names

Midmenj
offline
Midmenj
216 posts
Nomad

yah thats what i ment. haha

Midmenj
offline
Midmenj
216 posts
Nomad

so what does that code do?

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Let's say you have symbol called Mario, and a symbol called Soccer Ball, then you give then instance names of &quotlayer" and "bal"

So your code would be

if(player.hitTest(ball))
{

}

And then put your code inside those brackets

Look at the name, "HIT TEST", it's testing for hits, and if the hit happen, it will run the code inside those brackets { }

dank
offline
dank
983 posts
Peasant

First of all, what version of AS are you using?

Midmenj
offline
Midmenj
216 posts
Nomad

um 2.0

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

So, what didn't you understand?

Midmenj
offline
Midmenj
216 posts
Nomad

After puting in the codes. what comes next? like how do i make that frame go to the next?

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Explain it a little more, what do you mean? You have a "Character getting hit" animation on another frame, is that?

Try to be specific

Midmenj
offline
Midmenj
216 posts
Nomad

Ok. What I am looking for is when a character is going to a new place like a door. It hits it and then he goes in through the next door in another fram to do that level. Also. When he is on a platform and falls off the platform he looses a life.

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

You can have a killing groud way below the platforms, as soon as he touches it, he dies

Imagining you're making separated keyframes and want to go from one to another, you just have to use "gotoAndStop(Frame)" where frame is the numbe rof the keyframe you want him to go

if(MyCharacter.hitTest(Door))
{
gotoAndStop(10);
}


Although it's a bit rough to just teleport the player like this
Showing 1-13 of 13