Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Ahronsilv · Nov 14, 2020 at 07:13 AM · 3dselectionaimingtop-down

Select enemies with buttons based on their position on scene

Hello. I am creating a top down RPG and need to build an aiming system. I want my character in a battle mode to lock on target and then select between targets on arrow buttons. The select should be performed based on a location and a distance between enemies, that are constantly moving. Like first you select the closest enemy to you, then closest to him and so on. And of course, in a chosen direction. If you have an enemy in front and in back of you, when you press ARROW UP, you should lock on an enemy in front, and when arrow down, then you lock on an enemy in back. If you keep pressing ARROW UP, then you must lock on an enemy that is located upwards from your current selected enemy, and so on. The scene is 3D, and as objects are constantly moving, I am unable to create an array or something. Please, help, I really have no idea of how I can do this.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Llama_w_2Ls · Nov 14, 2020 at 04:18 PM

This solution could be very inefficient depending on how many enemies you have, but first create an array of enemy gameobjects in the scene.

Then, iterate through the array and fire a raycast from your player to the enemy player, and get the distance between them. Add this distance alongside the enemy GO that you hit with the raycast, preferably into a dictionary.

Finally, sort the dictionary by distance to get the GO's that are closest to you. All this happens in the update, so the enemies can be constantly moving, but you still have a list/dictionary containing the closest enemy GO's to the player.

Then, by pressing ARROW UP, you can go through the dictionary, highlighting the closest enemies in order.

If you need help coding any of the steps, then ill give it a shot. @Ahronsilv

Comment
Add comment · Show 2 · 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
avatar image Ahronsilv · Nov 14, 2020 at 09:08 PM 0
Share

Thank you so much, this idea is quite helpful with few enemies, like 4-5 enemies on the map. But I still need to find out how to sort array depending on direction. Like, the first enemy in front of me, the first enemy from the backside, the first from the left, the first from the right.... This really frustrates me

avatar image Llama_w_2Ls Ahronsilv · Nov 15, 2020 at 06:37 AM 0
Share

Well you could do the same style of sorting, but with a list containing the angle between your player's forward direction, and the direction of the raycast, the lower the angle, the closer it is to the front of your player. I guess you could try that?

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.

Follow this Question

Answers Answers and Comments

184 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Plese help to create custom top-down light? 0 Answers

Looking for advice for an isometric aiming system and soft grid system 1 Answer

Using mouse for realistic Top-Down space ship yaw control 1 Answer

Top-down 2D motion in 3D game 1 Answer

A 2D GUI in mid air, for oculus, tracking an object. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges