-
Hero stops on hitTest
http://www.saskgmperformance.org/Brad/HMPort.fla
http://www.saskgmperformance.org/Brad/HMPort.swf
I'm trying to make a port of an old game, but I haven't used flash in a long time.
So if you run the .swf and walk onto a weed or rock you'll see the problem I'm having. I have the code set up so that if there is no hitTest the character will respond to the keyboard.
But, when there is a hitTest he gets stuck. I've tried making him go in the opposite direction until the hitTest returns false, but this turns out sloppy and buggy.
I have to test for multiple, duplicated movie clips, so I'm having trouble finding a method that will work for me.
Yes I searched
Thanks in advance.
Last edited by brad_sk88; 12-11-2006 at 03:41 PM.
-
M.D.
perform the hitTest after you have updated your position with velocity, then render new position when all calculations have finished
if(key.isDown(Key.RIGHT)) x += speed
if(Key.isDown(Key.LEFT)) x -= speed
if(_root.bounds.hitTest(x, y, true)) //do hit
_x = x
_y = y
-
Okay, so now I have
Code:
for(i = 0; i <= 200; i++){
if(!this.hitBox.hitTest(_root["obstacle"+i].hitBox)){
this._x = x;
this._y = y;
}
}
other stuff
if(Key.isDown(Key.UP)){
if(Key.isDown(Key.SHIFT)){ //Player runs when shift is held with controls
this.gotoAndStop("RunN");
y -= 6;
}else{
this.gotoAndStop("WalkN");
y -= 2;
}
}
^^repeated for each keystroke
But now the hero doesn't move at all.
Last edited by brad_sk88; 12-05-2006 at 04:39 AM.
-
You probably need a switch, otherwise it continually does the action uncer hittest, so it keeps sending and resending your hero to a given frame. Should have and hit!= 1 when testing for hit, and then switch hit = 1 after he's hit and sent to a frame you need to send it to. Then just reset this to 0 or whatever as needed ( hit animation completed ).
-
M.D.
Originally Posted by brad_sk88
Okay, so now I have
Code:
for(i = 0; i <= 200; i++){
if(!this.hitBox.hitTest(_root["obstacle"+i].hitBox)){
this._x = x;
this._y = y;
}
}
other stuff
if(Key.isDown(Key.UP)){
if(Key.isDown(Key.SHIFT)){ //Player runs when shift is held with controls
this.gotoAndStop("RunN");
y -= 6;
}else{
this.gotoAndStop("WalkN");
y -= 2;
}
}
^^repeated for each keystroke
But now the hero doesn't move at all.
x and y cannot be temporary variables, in you loop trace out what x and y are. To use this method (bounding box hitTest) you'll need to update your coordinates before the hit, because hitTest uses your _x and _y movieclip coordinates for a bounding box hitTest. In my original post i used shapeflag which tests a point against a shape. So in order to use a bounding box method you will have to project your movieclip out of the collision. A common way is to just use the inverted velocity. But this will make your movieclip act sticky to the object when trying to move diagonally along it
Last edited by mr_malee; 12-05-2006 at 07:30 PM.
-
The diagonal thing isn't a problem, this is a direct port and the original game had no diagonal movement, just 4 way. I may change it later but for now I'm keeping it that way.
Unfortunately, I don't know how to use the 'inverted velocity,' can you elaborate?
-
M.D.
i'm not sure what the correct term is, velocity, speed, acceleration or force but basically its the:
var speed = 6 bit
_x += speed
if you collide, simply say, _x -= speed
-
I've done that, but when you turn around while the hero is 'bouncing' away you slide backwards over the object....
-
M.D.
-
Wow, that's so simple, yet I would have never thought of it on my own.. Thanks.
-
i dunno if you have the framerate set to low or not. but it is very very choppy.
i think this could be because of your for loop of 200 hittests. From looking at your game, the rocks/bushes look the same size as the character. I would suggest using a tile engine. It will speed things up a lot and make everything easier.
-
It's running fine on my computer, anyone else having issues with speed?
(link is in first post)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|