Preventing collision with 2 objects at the same time
I have an actor that is being used like a ball and is being thrown towards a target.
I want the target to have different point values depending on where you hit it.
So the way I did this was to create different actors for each section of the target and put a collision rule on each of them that adds a certain number of points to the player's score.
The ball itself has a rule that tells it to stop, do a quick animation, then destroy itself when it collides with the target.
The problem I'm having is that sometimes my ball is hitting two of the target actors at the same time and it's giving the player the score value for both of those target actors.
Any strategy for dealing with this?
I want the target to have different point values depending on where you hit it.
So the way I did this was to create different actors for each section of the target and put a collision rule on each of them that adds a certain number of points to the player's score.
The ball itself has a rule that tells it to stop, do a quick animation, then destroy itself when it collides with the target.
The problem I'm having is that sometimes my ball is hitting two of the target actors at the same time and it's giving the player the score value for both of those target actors.
Any strategy for dealing with this?
Answers
Another fix might be to have a game-level boolean (e.g. game.HitTarget) that gets set to true when either target collision actor is hit and have a rule on each collision actor that only runs when that boolean is false.
I thought about using one actor for the target and checking the position. But I wanted to have the flexibility to move the different target zones around and change their size from level to level. Having just 3 actor types (bullseye, one level out, two levels out) would make this easy.
I'll play around with the boolean flag idea and see if that works for me.
I think I'll try uptimistik's suggestion. To keep the flexibility of changing the positions for each level, I think I can use scene level attributes, right?
If your making it for ipad and using the x y position then you would have to alter it manually because the target would be bigger.
Darren.
If its a block sitting horizontally at the top with higher points towards the centre thats what i would do.
If its a round actor your using for the target i think the best would be to check its X to the targets X.
Darren.
So what I ended up doing is creating one target actor and defining game level attributes for the center position of the target and the size of each target zone. The collision rule for the ball compares the ball's position to the center position of the target and checks if it's within the specified distance for each zone.
This seems to be working well. If I want to change the position or size of the target zones for each level, I'll just need to change those game level attributes.