Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Topthink · Dec 19, 2016 at 05:41 PM · navigationindependent

How Do I get Units to Move to Different Locations?

I keep coming back to this because this is still an issue to me. I switched my focus to other Unity and C# studies but now I'm back. I've seen some videos. Still stuck.

Situation:

I have a small Terrain and two spheres. I want to give orders to each sphere separately to move to different locations...at the same time though. I want to do it in a "classic" RTS fashion (Ideally, anyway) by left mouse click on unit and then right mouse click on destination.

I'm thinking I need a private bool isSelected switch for the left mouse click and then some sort of raycast to mark the destination. But I can't quite figure out exactly how to write this in code.

I know how to use raycasting...I can make ALL the units go to a single right-click location, that's easy...I just can't make two units go to separate locations at the same time. I've done all this with physics, without physics, with NavMesh and without NavMesh...all of that.

Bummer. I've been spending a lot of time on this but I feel like I'm missing something really basic that's keeping me from accomplishing my task.

Comment
Add comment · Show 5
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 Topthink · Dec 19, 2016 at 06:21 PM 0
Share

Because of the very slow time frames involved, there is no need for me to give movement orders to more than one unit at a time...so I won't need to drag/drop/move a group of objects like you see in most RTS games.

I just need to click on a single unit and move it to a specific location...and each object must move independently of the others.

avatar image Cherno · Dec 19, 2016 at 06:27 PM 1
Share

In your mouse control script, have a variable that holds a reference to the selected unit. That measn that when you select a unit by clicking on it, that variable is filled iwth the unit reference (GameObject, transform, or any script on the unit, for example).

Each unit obviously has some kind of movement script so when you click to move a selected unit, you access it with the variable reference and access it'S movement script, and set the target position., and possible tell the movement script that it's ok to start moving now, search a path etc.

avatar image Topthink Cherno · Dec 19, 2016 at 06:34 PM 0
Share

Thanks Cherno, I'm looking at your suggestion right now. I'm going to try to finally figure this out and I appreciate your help.

avatar image Topthink Cherno · Dec 19, 2016 at 08:52 PM 0
Share

Got it. Finally.

avatar image Topthink Cherno · Dec 19, 2016 at 08:53 PM 0
Share

I don't know how to "accept" your answer since it's a response.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Topthink · Dec 19, 2016 at 08:55 PM

Cherno. I finally got this to do exactly what I want...I finally understand it.

I'm not sure why it took me multiple questions over a long period for this to finally sink in...but you finally made it understandable for me.

How do I accept your answer since it's not a separate comment?

Comment
Add comment · Show 1 · 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 Topthink · Dec 19, 2016 at 09:00 PM 0
Share

I'm just as happy as can be. This has been an enormous barrier to me and I finally got it.

If you could see me now, you'd see a happy programmer jumping up and down for joy.

:)

avatar image
0

Answer by DJGhostViper · Dec 19, 2016 at 09:00 PM

You cannot accept comments as answers sorry.

Comment
Add comment · Show 1 · 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 Topthink · Dec 19, 2016 at 09:40 PM 0
Share

Thanks. I didn't know 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

63 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

Related Questions

How to make object to avoid other objects? 2 Answers

NavMeshAgent not fully reaching destination, thus it won't delete itself when it gets there 1 Answer

How to generate a NavMesh only with colliders? 5 Answers

Get NavMeshAgents (Enemies) to not bunch up together 3 Answers

how to navigate through buttons? 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