Forums

ForumsProgramming Forum

why do movie clips not stop immediately when using hitTest?

Thread Locked

Posted Feb 7, '08 at 6:57pm

Koshionos

Koshionos

702 posts

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



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

 

Posted Feb 7, '08 at 8:16pm

dank

dank

1,045 posts

Knight

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

 

Posted Feb 7, '08 at 8:19pm

Koshionos

Koshionos

702 posts

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

 

Posted Feb 7, '08 at 8:26pm

dank

dank

1,045 posts

Knight

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--
}

 

Posted Feb 8, '08 at 6:46pm

Koshionos

Koshionos

702 posts

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