An object detecting another object?
BonepileGames
Member Posts: 194
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.
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
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).
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support