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 Eco-Editor · Jul 03, 2017 at 07:53 PM · intstate machinewaypoint systemdestination

Store information of distination to use in next script

Hello everybody,

The question is: how can I store the int information to be used farther in a script?

and here's the line of code I use:

 public int nextWayPoint;
 
  public void Patrol()
 {
 shopper.navMeshAgent.destination = SceneIndex.instance.waypoints[nextWayPoint].position;
 }

[nextwayPoint] is an int.

I would like to make a transfrom varibale like "currentwayPoint" and say currentwayPoint = nextwayPoint. like: SceneIndex.instance.waypoints[currentwayPoint].position But I can't because it has to be something associated with ints...

EDIT PHOTOS ADDED: alt text alt text

turning-to-opposite-directions1.jpg (58.3 kB)
turning-to-opposite-directions.jpg (35.0 kB)
Comment
Add comment · Show 2
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 ShadyProductions · Jul 11, 2017 at 11:24 AM 0
Share

What you are saying makes no sense, can you further elaborate?

avatar image Eco-Editor ShadyProductions · Jul 11, 2017 at 11:34 AM 0
Share

Yes of course. I have an array of way points. the ai is going from one to another.

 nextWayPoint = (nextWayPoint + 1) % SceneIndex.instance.waypointTransforms.Length;

this is the line for patroling. this is the line for setting the destination:

 shopper.nav$$anonymous$$eshAgent.destination = SceneIndex.instance.waypointTransforms[nextWayPoint].targetTransform.position;

At this moment , is it correct to say that the AI is going to a specific destination, and what going to define that destination is the int within the square brackets [nextwayPoint]?

If so, is it posible that farther in the code if I want to adress this destination I should be able to do so?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fvde · Jul 11, 2017 at 11:30 AM

@Eco-Editor nextwayPoint is an Integer which cannot hold a reference to a Vector3. I would suggest you store the Transform as the next waypoint, like this:

Transform nextwayPoint = SceneIndex.instance.waypoints[currentwayPoint]

Then you can use it moving forward like this:

nextwayPoint.position

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

Answer by Eco-Editor · Jul 12, 2017 at 08:01 PM

@fvde hi, Im no expert but I think the whole idea of having "nextWayPoint" as an integer is because of the function that uses % sign for deciding what point is next.

             wayPoint = (nextWayPoint + 1) % points.Length;
         }

How else would you reference the next wayPoint?

Comment
Add comment · Show 3 · 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 ShadyProductions · Jul 12, 2017 at 08:12 PM 0
Share

Why don't you ins$$anonymous$$d do something like this:

     public int currentWayPoint = 0;
     public int nextWayPoint
     {
         get
         {
             currentWayPoint = (currentWayPoint + 1) % points.Length;
             return currentWayPoint;
         }
     }

that way you can use currentWayPoint further down in your script, and everytime you need a new waypoint you can just use nextWayPoint and it will update the current waypoint aswel.

avatar image Eco-Editor ShadyProductions · Jul 15, 2017 at 03:08 PM 0
Share

Hello @ShadyProductions and all,

Perhaps a picture is worth a thousand words: In the picture (above) you can see my wayPoints on the ground. Each has a blue local arrow pointing to the shelf, e.g, Point 1 is pointing downwards, whereas point 3 is pointing upwards (in this photo), and an avatar supposed to face the shelf, using transform. forward.

In the second photo (above), you see how my destination point is different from turning point. If you look at the three button lines, the avatar is at point 4 (it is in the photo), but is facing the turning point, point 3 (also in the photo).

Why is that happening?

avatar image Eco-Editor Eco-Editor · Jul 15, 2017 at 07:58 PM 0
Share

You can see that it's actually going backwards: destination is 2-> turning to 1,destination is 3-> turning to 2,destination is 4-> turning to 3 This is why I wanted to store the integer so it doesn't need to call the function again using: currentWayPoint = **(currentWayPoint + 1)** % points.Length;

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

66 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

Related Questions

Cannot convert 'callable(int) as float' to 'float'. 1 Answer

Object to int 1 Answer

c# convert int to string 2 Answers

Having a GUI text as a int 3 Answers

How to write "if (var int = var int 2)" ? 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