-
Try driving the grey ship through the wing of the green ship. The green ships shields will turn on but the grey ships won't. It makes game play very unfair because the green ship is considered to be hiting the grey ship more often resulting in more damage.
But I read somewhere that you can put hit points on each of the four corners or something and have it detect collision on anything between those (Something like that?) although I did not quite understand it.
-
bout that 4 points... ive been trying that - havnt got it to work:S other ppl have got it tho i tihnk... cyas...
-
I need to know how a MC stop in its track after hitting another MC? (walking then an obstacle in front so can't walk no more)
-
go like this
Code:
if(_root.movie1.hitTest(_x+x, _y+y, true){
speed = 0;
}
something like that... hope it helps
-
1 Attachment(s)
Quote:
Originally posted by leight
go like this
Code:
if(_root.movie1.hitTest(_x+x, _y+y, true){
speed = 0;
}
something like that... hope it helps
it still pass through the obstacle
onClipEvent (enterFrame) {
moveSpeed = 3
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
}
if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
}
if (_root.movie1.hitTest(_x+x, _y+y, true)){
speed *= 0;
}
}
-
:)
I couldn't have a look at ur .fla cuz my PC is flipping :(...
Anywayz... there are 2 errors in the code:
Your moving with the var 'moveSpeed', but when a hitTest is found... it changes the var 'speed'... I think that one should be moveSpeed
And you change the speed with *= 0... wich always return 0.. so why not jus' write speed = 0?
-
and where it says movie1, change that to the instance name that your doing the hitTest against...
-
so basically this is the code that will work.
onClipEvent (enterFrame) {
moveSpeed = 3
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
}
if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
}
if (_root.enemy.hitTest(_x+x, _y+y, true)){
moveSpeed = 0;
}
}
but it doesn't. apparently the moveSpeed = 0 isn't working
-
:)
Ok,
Heres what I've got.
Change the code to this:
onClipEvent (load) {
speed = 3;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x += speed;
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
} else if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (_root.movie1.hitTest(_x, _y, true)) {
speed = 0;
}
}
Another error I spotten was, in your code you're using a variable called x (in: _x+x) in the hitTest code... but that variable doesn't get a value anywhere?... so if it dfoesn't have a value... it shouldn't be used :D
-
but then why does it work for me with the hitTest??? i use this mostly, if (_root.walls.hitTest(_x+x, _y+y, true) and i just substitite in a number for y and x. that isnt a really good way, it only works for 1 point. and same with the ...(_x, _y, true), thats just only 1 point.
i cant get the empty mc's around the edges to work??? y is this???
Code:
if (_root.walls.hitTest(_root.car.empty))
speed = 0;
}
??? thanks
-
ok...
http://www.flashkit.com/board/showth...hreadid=446750
is tis possible? or too advanced?
there's this globaltolocal thing i have no idea wat to do with...
is tat important in makign this work?
-
I am working on a Tourny Map for this game a bunch of us play. I am going to have it auto-create the map layout to make it as easy as possible for future use. I got it laying out the N number of sectors on a background but now need a way for it to not use a new sector if its touching one that is currently on the map. I figured this would be a great use of HitTest but have not been able to get it to work. If you look at my code what is in RED is the HitTest overlap check. The code runs fine but it never finds the overlapping sectors. Do they have to be in the same depth?
Code:
N = 0;
Used = "";
do {
do {
Xdone = 0;
do {
Xrnd = Random(_level0._root.Xmax);
Xpos = Random(10);
if (Xpos <= 5) {
Xvalue = "-";
} else {
Xvalue = "";
}
X = Number(Xvalue + Xrnd);
if (X < _level0._root.Xmax) {
if (X > _level0._root.Xmin) {
Xdone = 1;
}
}
} while (Xdone <> 1);
Ydone = 0;
do {
Yrnd = Random(_level0._root.Ymax);
Ypos = Random(10);
if (Ypos <= 0) {
Yvalue = "-";
} else {
Yvalue = "";
}
Y = Number(Yvalue + Yrnd);
if (Y < _level0._root.Ymax) {
if (Y > _level0._root.Ymin) {
Ydone = 1;
}
}
} while (Ydone <> 1);
Search = "|"+X+","+Y+"|";
Found = Used.lastIndexOf(Search);
IsUnique = 0;
trace("Found: " + Found);
if (Found < 0) {
Used = Used + Search;
duplicateMovieClip("Sector", "Sector_" add N, N);
setProperty("Sector_" + N, _x, X);
setProperty("Sector_" + N, _y, Y);
trace("Used: " + Used);
if (N > 0) {
trace("More Than One Sector On the Map");
for (i=0; i<N; i++) {
if (_level0.Map["Sector"+N].hitTest(_level0.Map["Sector"+i])) {
IsUnique = 0;
trace("New Sector Touches Another Sector");
} else {
IsUnique = 1;
trace("New Sector Is Good");
}
}
} else {
IsUnique = 1;
trace("Only One Sector On The Map");
}
}
} while (IsUnique <> 1);
N = N+1;
} while (N <> _level0._root.Nsectors);
stop();
-
New Eyes!
Took a short break... got a drink and then looked at it again and BAM! Found two errors in the code that caused it not to work. If you guys want to know what the working one should look like here it is..
Just the hittest part...
Code:
if (N > 0) {
trace("More Than One Sector On the Map");
for (i=0; i<N; i++) {
if (_level0.Map["Sector_"+N].hitTest(_level0.Map["Sector_"+i])) {
IsUnique = 0;
removeMovieClip("Sector_" + N);
i = N;
trace("New Sector Touches Another Sector");
} else {
IsUnique = 1;
trace("New Sector Is Good");
}
}
} else {
IsUnique = 1;
trace("Only One Sector On The Map");
}
}
} while (IsUnique <> 1);
-
Hey, I was just having a little trouble with some massive hittest in my game and i came here for some help. I'm trying to put some code in my game that checks if the player object touches ANYTHING. The way i've set up my code I don't and can't have any instance names for my objects so I'd like to know if there is anyway of checking if the hero clip is touching anything. Here is the kind of code i'm looking for: if (this, hittest(ANYTHING)) {
-
i dont think there is - just make everything that u wana make the hitTest against in one big MC and name it anything... there ya go - simple:D
-
an example of hitTest vs. programmed collisions, hold space to increase speed.
http://www.lukstr.no-ip.com/flash/hi...snohittest.swf
-
wow - i like the non hitTest beta!!! how do u do that??? also how do u do the empty mc on four corners??? i get stuck
-
it's no "beta". I merely programmed some boundries for the ball and made it go, then made it "bounce" when it reached the boundries. I don't know what you're talking about when you say "empty mc", the only MCs are the balls, and some walls for the hitTest example.
-
leight, create a circular MC and paste this code on it (centred), and apply this to it
Code:
onClipEvent (load) {
vx = random (20) - 10;
vy = random (20) - 10;
bound = {xmin:0, xmax:400, ymin:0, ymax:400};
radius = _width / 2;
};
onClipEvent (enterFrame) {
// work out the next positions
xpos = _x + vx;
ypos = _y + vy;
// check to see if the next position is outside the boundaries
if (xpos + radius > bound.xmax) {
vx = -vx;
xpos = bound.xmax - radius;
} else if (xpos - radius < bound.xmin) {
vx = -vx;
xpos = bound.xmin + radius;
}
if (ypos + radius > bound.ymax) {
vy = -vy;
ypos = bound.ymax - radius;
} else if (ypos - radius < bound.ymin) {
vy = -vy;
ypos = bound.ymin + radius;
}
_x = xpos;
_y = ypos;
};
-
hey thats kool - but how about for a car??? puting mc's on teh edges and using those to do the hitTest???