PDA

View Full Version : hitTest for a game


cuba
03-08-2002, 09:07 AM
Hello

I'm swiss. I hope you'll understand my english. I have the following problem: I'm creating a game. I have a flying helicopter
which can land on mountains or platforms. I'd like to attach a
charakter (man) on a mountain. I want to pick up the man with the helicopter, and drop it again on a different area. I have the
following script attached to the "man" charakter:
onClipEvent(enterFrame) {
if(hitTest("_parent.heli")) {
_x=_parent.heli._x;
_y=_parent.heli._y;
(_parent.heli._height/2);
}
This works to attach the man to the heli, but it hides the charakter
behing the heli, i want it to be attached under the heli.
What do I have to change???

How can I drop the charakter over a different area ???

thanks in advance for any help, tips or examples

regards
cuba

sfa
03-08-2002, 09:41 AM
You either have to move the man character inside the movie or change the line _y=_parent.heli._y; to _y=_parent.heli._y + 10;(change ten depending on the size of the helicopter). The x will be defined from the centre of the movie. I would go for the first option and keep it simple.

SFA

IFZen
03-08-2002, 09:41 AM
Hi cuba,

If your rescued people are attached mc's, you should consider at least two scenarios for them. The first one as you wrote it allow you to find them on mountains. Then, when they hit the chopper, you could destroy their first occurence and attach them again into the chopper clip (there you also could place their clips between a front clip of your chopper and a background clip to give a good illusion they seat inside the chopper).

At the end you will also have to imagine a third scenario when you arrive at your base, allowing them to get off the chopper and have a nice cup of tea into the base.

One good point with that way is that you won't have to perpetually execute your enterFrame code after you rescued your people. Into the chopper they won't have to do nothing but wait for safe landing.

Hope you understood me.
BZen

cuba
03-08-2002, 11:26 AM
thanks i will try this. but how can i drop the "character", with
_droptarget ???? or do you have another idea???

thanks a lot

regards
cuba

IFZen
03-08-2002, 12:48 PM
You can use the same hitTest method on your base to check when your chopper lands and then automaticly launch an animation showing your rescued characters being saved. Just before destroy their instancies into the chopper.

Hope it helps,
BZen

cuba
03-10-2002, 08:40 AM
Hi mozilla

I tried to attach your sample script to the character man, but
it doesn't work. I think i need to attach a script to the helicopter,
because it can land without any problem.

I didn't understood the "trace"-thing, i always had a debugger
window: with the "not allowed to land window"...

I hope that you understand me...

Thanks again for your kind help !






Hi again (Thanks Mozilla for your reply)

I have still the problem, that it's possible to land, without going
to save the person (character:man)
If the player wants to land, without having saved the person, a
message should appear: "not allowed to land, save the person"
I have the following actions for the helicopter to land:
function checkForLand () {
landed = true;
for (i=0; i<footPoints.length; i++) {
footDown = false;
for (j=0; j<bars.length; j++) {
if (bars[j].hitTest(heli._x+footPoints[i].x, heli._y+footPoints[i].y, true)) {
footDown = true;
break;
}
}
if (!footDown) {
landed = false;
break;
}
}
if (heli.dy>3.0) {
landed = false;
}
if (landed) {
gotoAndPlay (_currentframe+1);
gameLevel++;

And these actions are for the character:

onClipEvent (enterFrame) {
if (hitTest("_parent.heli")) {
_x = _parent.heli._x;
_y = _parent.heli._y+50;
(_parent.heli._height/2);
}
}
onClipEvent (enterFrame) {
if (hitTest("_parent.hospital1")) {
_x = _parent.hospital1._x-0;
_y = _parent.hospital1._y-1;
(_parent.hospital1._height/2);
}
}
Thanks in advance for your help... regards from zurich, switzerland
cuba

mozilla
03-10-2002, 12:48 PM
did you try? what didn't work? please specify problem. (or post fla)

greeZ