"Sensitive Area" position locked to another actor
![edufiend](http://forums.gamesalad.com/applications/dashboard/design/images/defaulticon.png)
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!
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
-
domenius Posts: 108
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
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.
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.