View Full Version : [AS2] hitTest, dont walk through barrier / wall.
ProdigalMabilis
05-02-2009, 06:10 PM
Hi, here's a typical problem. 'speed' is the speed that the character can move. I have a block called 'collisionmap' and a character called 'perso', not person. The player ('perso') is in the center of the stage, and when you move, the surroundings move so this is called 'scrolling'. BUT, when you walk into the block ('collisionmap') i want it so you stop and cannot pass through it. The reall bad code below kinda works but, as experts will notice it wont properly, my code bounces weirdly off the wall aswell....instead of stopping against the block. If you get close enough to the block and stop, you can move backwards into the block.. if that made sense.
Anyway, can anyone help me? i just want it to not pass through the block and to be able to walk up against the block.
Thanks, heres the code:
collisionmap.onEnterFrame = function() {
if (this.hitTest(perso)) {
_root.speed = -2;
} else {
_root.speed = 3;
}
};
ProdigalMabilis
05-03-2009, 01:43 AM
Still no reply? my post is under that advert... hello??
ProdigalMabilis
05-03-2009, 09:22 PM
collisionmap.onEnterFrame = function() {
if (this.hitTest(perso)) {
_root.speed = -2;
} else {
_root.speed = 3;
}
};
I need it so my character cannot pass through or get stuck inside a block, which is a barrier or wall.
collisionmap = block
perso = charcter
speed = speed of character.
Thanks for any help you give.
raskolnik
05-03-2009, 10:02 PM
Why are you setting the speed to -2 and not 0?
ProdigalMabilis
05-03-2009, 11:13 PM
I asked at another forum.. the adobe one and, they answered my question within about an hour. Here, iv just got a reply.. not answering my question, thats after aout 2 days...
ANSWER: _root.speed = -_root.speed;
ProdigalMabilis
05-03-2009, 11:15 PM
Why are you setting the speed to -2 and not 0?
Well, Ofcourse iv tried 0 , im not that dumb. But if you set it to 0, you get stuck in the block and cannot move.. as your speed is 0 whilst youve hit the block.. -2 works better but is verry buggy... anyway, i got the answer on anohter forum.
scarce
05-04-2009, 06:56 AM
I asked at another forum.. the adobe one and, they answered my question within about an hour. Here, iv just got a reply.. not answering my question, thats after aout 2 days...
ANSWER: _root.speed = -_root.speed;
no one answered because this question is on the forum about a million times. search the foorums, it does wonders.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.