by skydereign » Wed Oct 12, 2011 1:11 am
I know, and the explanations I have given are doing just that. The only problem is that if your game is going 30fps, and your enemies attack animation lasts for longer than 1/30th of a second, then if you set the collision event to repeat, then the enemy will pretty much be guaranteed to hit the player. For instance, if the attack only lasted one second, and your game runs at 30fps, then they have 30 attempts at hitting the player with a 50-50 chance. That means the chances of not getting hit are 1/1,073,741,824. I'm pretty sure that isn't what you meant by 50% chance of blocking. Therefore you need to limit the number of attempts to 1. You can do this by adding a variable that holds how many attempts are allowed, and whether the attempt succeeded or not, lower it.
So when the enemy attacks, set the variable to 1. When it collides with the player, check if it is greater than zero, and if so, try to hit the player. Regardless of the actual attack's result, lower the variable by 1 (normally to zero).