An object detecting another object?

Hello to GS community,

I have been banging my head trying to come up with a way to implement one awesome feature in my game.

I would like to have an object (e.g a red square 12x12), which detects another object. For example, the objective is to the right of the main actor but it can't be seen at that moment because it is, let's say 1500 pixels to the right. It should be something like an object giving you direction where the objective is and always showing you the right direction as you move around the map. I imagine the "red square" to be a part of a circle which is invisible around the main actor.

Does anyone have any ideas how to code that thing?

Thank you.

Comments

  • ArmellineArmelline Member, PRO Posts: 5,459
    edited February 2014
    This can be done without too much trouble if the detecting object always knows the name of the object it is trying to detect.

    This video by tshirtbooth will get you going in the right direction:



    Presumably you could do something like have an arrow on a non-scrollable layer that is working out how far away it is on the x and y axis from the actor it is detecting, and pointing accordingly.

    Edit: Thinking about it some more, I distinctly remember downloading a template that had eyes following an actor around the screen. Not sure who it was by, but a bit of googling will probably turn it up.

    Edit 2: Okay I threw together a quick example. The first scene, labelled "Static", is the previous template as best as I can remember (or just assume this is how it was done).

    If you want a larger scene that will be moved around, it gets a little trickier. GameSalad is a bit huffy when it comes to layers, so I constrained the arrow to the actor that controls camera movement. I can't imagine many situations where this wouldn't work for a tight following of the camera, but you'll have to come up with a better way if your tracking area is large.

    At the very least, this hopefully gives you some ideas! (Attachment on next post as it seems I can't attach to an edit).
  • ArmellineArmelline Member, PRO Posts: 5,459
    And the file!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I have a mini map demo and oh, @Armelline that's my eyes following template... :)

    http://forums.gamesalad.com/discussion/comment/436556/#Comment_436556
    http://forums.gamesalad.com/discussion/comment/384027/#Comment_384027

    (Also, if you scroll down a little from that second link, you'll find an improved version by @Socks).
  • ArmellineArmelline Member, PRO Posts: 5,459
    edited February 2014
    I knew it would be someone here's :D Looks like when I threw together the example above it was Sock's method I used, though :D

    Like Socks I used an unlocked actor for the static example, but you could definitely use a couple of constrains and use a locked actor, if you preferred.
Sign In or Register to comment.