|
-
[F8] [HELP] Hittest
I am having a noticeable problem with my game.
When the player is next to a hit test (a wall) and walks into it, the player moves over the hit test and then bounces back.
Like So.
Player movement detected, player moves + 5 on the y axis. Then the hit test registers the players movement and subtracts 5. At first when the player tried to move to the object it appeared that the player ddint move at all. But now the player moves + 5 and then - 5, instead of appearing like 0. I don't understand why all of a sudden this happens!
player code
Code:
player.onEnterFrame = function() {
if (!_level0.pausemove) {
this.swapDepths(this._y);
// <To walk>
if (Key.isDown(38)) {
this.gotoAndStop(5);
this._y -= _level0.speed;
_level0.this_lastfaced = 1;
} else {
if (Key.isDown(40)) {
this.gotoAndStop(7);
this._y += _level0.speed;
_level0.this_lastfaced = 3;
} else {
if (Key.isDown(37)) {
this.gotoAndStop(8);
this._x -= _level0.speed;
_level0.this_lastfaced = 4;
} else {
if (Key.isDown(39)) {
this.gotoAndStop(6);
this._x += _level0.speed;
_level0.this_lastfaced = 2;
}
}
}
}
// <\To Walk>
if (!Key.isDown(37) && !Key.isDown(38) && !Key.isDown(39) && !Key.isDown(40)) {
this.gotoAndStop(_level0.this_lastfaced);
}
} else {
this.gotoAndStop(_level0.this_lastfaced);
}
};
(this code is on the main frame)
This following code appears in the action script panel of a movie clip within a movie clip that is called via "attachMovie"
Code:
onClipEvent (enterFrame) {
if (this.hitTest(_parent._parent.player.testhit)) {
trace("player touching fence");
_parent._parent.player._x += _level0.speed;
trace("sub speed");
}
}
At first it worked fine, but all of a sudden it messed up and now it makes the player "bob" or "bounce". Any ideas?
-
hmm!
the introduction of a second frame within the main time line or even withing a movie clip causes this! I am not sure if this would change anything but this .swf file is loaded into another swf file and played.
I hope some one can help!
-
Senior Member
Thats quite normal if you think about the game logic:
*move the player
*check for hittest
*move away from the wall if player hits it
Correct way to avoid such problem would be checking the point first where player would end up if it would move (but not actually moving the player yet). Only when its next position is clear will you apply movement to the player:
*create new point with speed value added to the current position of player
*use this point to test collision with all the walls
*if the point does not detect any collision, move the player
*if collision is detected, leave the player in last position
-
hmm
Your way is good, but I will have to recode it :P.
I just find it odd that when I add another frame it bobs... If its always supposed to have that bob then why didn't it until I added a new frame..
maybe i should upload my code for you so you can see ?
Tags for this Thread
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
|