PDA

View Full Version : Hittest inside mc


Ragnarmb
06-20-2007, 09:26 PM
Hi!

I'm making a game (not rpg) with a scrolling map. I have the movements going, but I'm having problems with the hittesting. Becasue i need to hittest my character (which is centered) with walls and stuff inside the map. The problem is that the walls inside the map has got their position relative to the map. I have tried to make the map coordinates fit exactly with the _root, but with no success.

I hope you understand my problem, and I'm grateful for any answers!

gankro
06-20-2007, 11:39 PM
well... you'll have to be more specific... if it's not tile based use shapeflag hitTests... if it is tilebased... there is something wrong with yuor code

Ragnarmb
06-21-2007, 05:42 PM
Sorry!

Forget everything I said over there...

take a look at this file:

http://ungkristen.com/smootown/smooflash/0.01.fla


Its not tilebased. What I want is to make the character (the circle with the arrow for the moment) not to get stuck when it hits the walls. Would also be great with some help to have shape vs shape hittesting.

Please be spesific with your answers, I have asked others, but I usually get a general answer that doesnt do any good. I need some practical help.

Thanks!

Seanx
06-21-2007, 06:36 PM
I tried dl fla file - said 'unexpected file format' - sorry

Ragnarmb
06-21-2007, 06:48 PM
bah, it was saved with flash cs3, try again, ive replaced it with the same file, for flash 8

Seanx
06-21-2007, 07:01 PM
are you asking why the circle can get halfway into the wall before being rebuffed?

Ragnarmb
06-21-2007, 07:08 PM
Yep... or, well, I know why, but I don't know a good solution.

But my main question was how to make it that it doesnt bumb each time you go into a wall. It's better if it just slides with the wall or just stops (and than make it able for it to move again).

Seanx
06-21-2007, 07:16 PM
well sliding with the wall or just stopping, you'd have to put a conditional in there like instead of:

if (Key.isDown(Key.LEFT)) {
xmove = _root.world._x+power;
_root.mainguy.gotoAndStop(4);
}


go:


if (Key.isDown(Key.LEFT)&&someVariableSetToTrueIfCircleHitsWall) {
xmove = _root.world._x+power;
_root.mainguy.gotoAndStop(4);
}


if you did this for all of your key is down if statements then it could slide along the wall

EDIT: crap - I'm sorry - that's dumb too - it would have to be a different variable for going up down left and right rather than one - otherwise your circle would just freeze as soon as it came into contact with a wall

Ragnarmb
06-21-2007, 07:21 PM
So I should run a hittest, and if it hits, then that variable is true?

But, doesn't that make the guy get stuck? Because if it hits, none of the if statements will go through..?

Seanx
06-21-2007, 07:34 PM
that's why I edited to say you'd need four variables one for each direction - but yes - that's how I'd do it, as dumb as it may sound - there's probably a much better way

Ragnarmb
06-21-2007, 07:56 PM
ok! Thanks, ill try that out ;)

Ragnarmb
06-21-2007, 08:22 PM
Ive tried your fix by making 4 mcs inside mainguy, but for some reason its hitting all over the place. Ive updated the file here:

http://ungkristen.com/smootown/smooflash/0.01.fla

gankro
06-21-2007, 09:00 PM
why don't you just put this code inside the MC and customize it for yuor rotations...

onClipEvent(enterFrame){

if(Key.isDown(Key.UP)){
this._y -= 3;
}else if(Key.isDown(Key.DOWN)){
this._y += 3;
}
if(Key.isDown(Key.LEFT)){
this._x -= 3;
}else if(Key.isDown(Key.RIGHT)){
this._x += 3;
}
if(_root.maze.hitTest(_x+(_width/2),_y,true)){
this._x -= 3;
}
if(_root.maze.hitTest(_x-(_width/2),_y,true)){
this._x += 3;
}
if(_root.maze.hitTest(_x,_y+(_height/2),true)){
this._y -= 3;
}
if(_root.maze.hitTest(_x,_y-(_height/2),true)){
this._y += 3;
}
}

//(name the walls "maze")