• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by RafiXWPT · Oct 15, 2015 at 12:53 AM · collisiontriggerdetectionrange

Get list of enemies in range

Hello, I am creating simple Tower Defense game and I am facing problem with getting enemies in tower range. I can't figure out how to wrote tower script to check enemies in range of sphere. I want to do that without rigidbody on enemies cus if I add it to them they are bouncing and won't use navmesh correctly. Can someone tell me how I can solve it correctly? I tried with ontriggerenter/exit but it seems I am doing something wrong cus no collisions is detected.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MadDevil · Oct 15, 2015 at 05:31 AM 0
Share

you can make a small script and attach it to enemy, which will continuously check the distance between the tower and enemy.

like,

float dist = vector3.distance(enemy.position, tower.potion);

if the value of dist is less than certain value, tower will start attacking the enemy.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hexagonius · Oct 15, 2015 at 05:54 AM

Its fine to use sphere collider on enemy as long as they're set to trigger. with the collision code, mind the upper cases. I'd also put the detection into the tower. one call on 20 enemies is cheaper than 20 calls to 1 tower.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

35 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision detection between target and sphere not working (3d),Collision between target and sphere not working (3D) 0 Answers

How to get "on trigger enter"( or exit) to only react to a specific tag 1 Answer

OnTriggerEnter2D not working 1 Answer

Javascript error on runtime semi colon required 1 Answer

How to let someone win in a racing game 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges