Preventing collision with 2 objects at the same time

mill4023mill4023 Member Posts: 9
edited July 2012 in Working with GS (Mac)
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?

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If your two areas are separated by a line (e.g. half of the target is one score, half of it is another score), you could get around this by checking the x/y position of the ball in relation to the x/y position of the target and awarding score based on that.

    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.
  • mill4023mill4023 Member Posts: 9
    Thanks guys.
    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.
  • mill4023mill4023 Member Posts: 9
    I tried the boolean and it doesn't seem to be working. I assumed that one collision event would be processed before the other, but they seem to be getting processed at the same time. If I set the boolean to not allow collisions as the last step in my rule, than both collisions still get fired. If I set it as the first step in my rule, I think only one one of the collisions get fired, but the rest of the events in the rule don't happen ( I guess because the conditions are no longer true). So I don't get the animation or the destruction of the actor.
    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?
  • mill4023mill4023 Member Posts: 9
    If I use one target actor and set the score based on position, do I need to do anything to handle multiple platforms with different resolution? In other words, do I need to set different numbers depending on whether it's running on iPhone or iPad? Or will GameSalad handle that for me?
  • UtopianGamesUtopianGames Member Posts: 5,692
    edited July 2012
    Have you got a pic of the target i might have an idea.

    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.
  • mill4023mill4023 Member Posts: 9
    It's a portrait oriented game. The target is basically a block that sits across the top of the screen. Think of it like skee ball or bowling, where the object is thrown from bottom to top and the goal is to hit the center. Fewer points are given for left and right side.
  • UtopianGamesUtopianGames Member Posts: 5,692
    edited July 2012
    Cant you use magnitude to get the distance of centre?

    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.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If I use one target actor and set the score based on position, do I need to do anything to handle multiple platforms with different resolution? In other words, do I need to set different numbers depending on whether it's running on iPhone or iPad? Or will GameSalad handle that for me?
    The position on the screen doesn't matter here. We're talking relative position (distance from target center, for example, as Darren mentioned).
  • mill4023mill4023 Member Posts: 9
    I wasn't sure how to get the target's center position since the collision rule is on the actor that's being thrown, not the target. That seemed to be the easiest way to set it up. Since the ball knows it's collided with the target, it can run the destruction animation and destroy itself in the collision rule. If I set the collision rule on the target, I wasn't sure how the target could reference the ball object to animate it and destroy it.

    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.
Sign In or Register to comment.