0 Favourites

# Object within angle and within range

• 15 posts
• EDIT: The problem has changed a bit. Please read the last posts.

Okay, a quick question:

How do I get the object which is inside a set angle of an other object AND within a specific distance in the set angle?

I have no problem getting an object that's within the angle but I don't know how to get the distance part.

• i would like you to search on forum about : tower

you will find some example may help you ^^ check these links you make use it :

http://www.scirra.com/forum/towerdefence-tower-aiming-first-enemy-in-range_topic53769.html?KW=tower

• Thank you! :)

Though it isn't really the most logical thing to get the word "tower" in my head when I'm looking for this ;)

Though your example is not doing what I'm looking for. This is just auto-rotating a turrent towards the player and then fireing of a bullet. What I'm creating is something of a "vision" system. And I need to detect whether the object is in a given "angle range".

Here is an example of what I mean: dl.dropbox.com/u/82642456/vision.jpg

EDIT: But actually I think I just came up with an idea that might work. I'll try that first. I think I just was a bit too tired when trying to do this last time.

• always remember there are many fans from all over the world so most of the tips are already posted of course you can ask and we will try to help you as much as we can :)

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Hmm..

I'm having some issues with this. I've set up a simple example to show it:

https://dl.dropbox.com/u/82642456/obstacle.capx

The idea is to get the distance to the Obstacle object in the set angle. Though this only applies for one of the object instances. What have I done wrong?

• ok i don't know the math stuffs if you use the sprites it will he us ^^ anyway change the 2nd event 2nd condition the 1st value change it from 45 to bot.angle+45 is this what you are looking for?

• I guess you didn't really understand what I was asking for. All the angles are set up correctly. That is not the problem.

The problem is that if you run the program you will see that we only get a distance reading from the right obstacle. And when the Bot object is facing the left obstacle we get no distance.

So the problem is that it only gets the distance from one of the object instances.

• I just noticed that if I set the Bot to face the left obstacle it only retrieves the distance for that object. So basically it only "sees" the object which it first looks at.

I hope someone will be able to help me with that.

• i'm not really sure what you really need but if you fix sprites it will be must better also you can put another sprite object for the facing so when the the red object collision with the facing sprite it will set obstacle

• Of course it is possible to go with an invisible "collision sprite" which is attached to the Bot object. But in my final application I will have a lot of objects on the scene at the same time and then it will be crucial for the performance to not having to use 2 sprites for each Bot object. As that will slow down performance.

• hmm if 2 sprite will slow the performance the events will do that too so easy events (so you can edit when ever you want) or hard event?

• But I'll have like 100 instances of the Bot class. And then there will be a quite big change to add 100 sprites more as I'm sure you understand.

That will effect the performance more than a couple of events.

Though I'm not sure if it's possible to do this with just events. So I might have to go with the collision sprite solution anyway.

• ok lets start over and explain what you want and use this instead of your box to know where you want the player to face

<img src="http://i47.tinypic.com/vncpr4.png" border="0" />

about 100sprites 0.0 what kind of game you will do? and does those sprites have animations or just 1 frame?

• I had a go at it, I'm not sure how stable it is, but you can give it a go if you want:

WithinDistanceAngle.capx (r97)

• Thank you Nimtrix!

As usual you delivered a perfect solution! :)

That was exactly what I was looking for!

• 15 posts