"Sensitive Area" position locked to another actor

edufiendedufiend Member Posts: 6
edited June 2012 in Working with GS (Mac)
Hello there, I have recently started using GameSalad and I'm very impressed with it, great job guys! Let's see, long story short: I am using the Paper Toss template to work on a game I have been commissioned with. I've got a main character that eats "food" actors that you throw with the touch controls. His mouth has an invisible actor that works as a sensitive area to determine whether the player has indeed succeeded in feeding the main actor. When the "food" touches the "sensitive sprite", it spawns another actor that executes the feeding animation in front of the original actor and then, after a timer, it destroys it.

My first question is, how can I attach the "sensitive area" sprite's position to the other actor's one? The actor will change its position during the game but I haven't been able to find a behaviour that will allow me to do that. Any help would be much appreciated.

PS: I've got a couple of other questions lined up regarding other subjects. Would it be better, to avoid clutter, to ask them separately?

Many thanks!

Best Answer

  • domeniusdomenius Posts: 108
    edited June 2012 Accepted Answer
    You're looking at some intense relative positioning math - seriously not fun. It would also require some constrains and generally slow calculations. I would try switching up the approach, use a magnitude calculation to determine if you are close enough to "food" and then measure the angle between your character and the food to tell if it is allowed to be picked up. Otherwise you're looking at trig functions and a ton of fiddling.

Answers

  • edufiendedufiend Member Posts: 6
    Thanks for the reply, I was hoping it would be a bit less of a hassle, maybe a third party plugin or something like that. But for the sake of argument, let's discuss a bit further your suggestion.

    Since I am fairly new to GS (but not a complete noob in terms of programming) let me see if I understand your idea. This "magnitude" operation you mention, I reckon it is in regards to the actual sprite's X & Y position, and how the sensitive area correlates to it, right? Would then the logic be something like this?

    On the main actor: create constrain attribute "sensitive_area"

    Rule: If main.actor touches or collides with food
    AND self.actor.sensitive_area is x and y then
    animate

    Is that close to what you meant? Thanks again.
  • edufiendedufiend Member Posts: 6
    Did I just close the thread by accepting your answer? Ouch, this forum noob is noob.
  • domeniusdomenius Member Posts: 108
    Magnitude is a very useful math function where you can insert your players x and y positions and your targets x and y positions to calculate the distance between them in pixels. If this distance is less than an acceptable range (how far you want the player to be able to grab food), you pass the first check.

    From there, we want to know if you are facing the right direction, I think vector to angle is your best bet to do that. Essentially it would be if the angle between the two actors (the food and the player) is within an acceptable range, we pass the second check.

    If we know that the range and angle are acceptable, we know the food is close enough to the actor and in front of them, we no longer need the "Sensitive spot" actor to define when the collection is allowed.

    Placing objects with relative positioning is quite easy until rotation is involved. Once thats the case, the complexity of the math jumps tenfold. Thats why I would recommend not using a separate actor to define the pickup conditions.
  • edufiendedufiend Member Posts: 6
    Brilliant, I will have to analyse closely your suggestion but I reckon that is the way to go. Since the food sprites are actually rotating (client's demand), I assume it would be better to make life easier through an animation, which thankfully, they have done already. Thanks again for your help mate.
  • edufiendedufiend Member Posts: 6
    Let's see if I'm on the right path. I have Saved Attributes of X and Y positions in 4 different magnitudes, two for each actor. Now, what would be the function or behaviour that I need to use to calculate the distance between them? I assume I would need to put this on the main actor. Thanks
Sign In or Register to comment.