ForumsProgramming Forumwhy do movie clips not stop immediately when using hitTest?

4 5682
Koshionos
offline
Koshionos
884 posts
Jester

what i mean is that when i put in the hitTest code



if (Player.hitTest(object)){
Player.dy = 0;
}

  • 4 Replies
dank
offline
dank
986 posts
Peasant

What are you saying? the hittest is set to true when an object's boundary's are collide with another's.

Koshionos
offline
Koshionos
884 posts
Jester

when ever i have my character fall even medium speed the character goes right past into the object

dank
offline
dank
986 posts
Peasant

That is because every frame the objects position will increment by the speed. Meaning if the speed is 5 and the object is 2 px from the ground, the object, falling straight down, will end up 3 px in to the ground.

The best way to do this is to move the object until it is hovering slightly above the ground. Here's a simple algorithm.

// while the object is touching the ground
while(player.hitTest(ground._x, ground._y, true)){
// move to contact
player._y--
}

Koshionos
offline
Koshionos
884 posts
Jester

unfortunately i tried that in my game and it didn't seem to do much good other than the player falling through thanks though I have found another way

Showing 1-4 of 4