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 /
  • Help Room /
This question was closed Jun 12, 2019 at 04:13 PM by NoodleCup for the following reason:

Other.

avatar image
0
Question by NoodleCup · Jun 11, 2019 at 12:33 AM · listtransform.positionwaypoint

Help with changing position of my waypoint.

Hello all, novice question for you. Im making a small pizza delivery game. Currently trying to get a Delivery Waypoint system in order. Someone earlier showed me the list function and I figured its perfect for what Id like to happen. The way I envision it is there are all the vector3 positions preselected on the map. I need one of them to fire off as the currentMarker and have the Gameobject I selected in the inspector (Red Waypoint Box) to be moved to the new currentMarker. Ive looked and searched but cant seem to write it in a way that unity understands whats the hell I want from it. Here is the script Im working with. Thanks in advance.

public class PositionFinder : MonoBehaviour { //Hold a list of all possible positions public List markerPositions = new List(); public GameObject Waypoint;

 //The active marker we are chasing
 public Vector3 currentMarker = Vector3.zero;

 //Call this function to start or when the user reaches a marker
 public void OnMarkerComplete()
 {
   HELP HERE // Waypoint.transform.position = new Vector3.currentMarker;

     //If we have markers remaining in our list we can find a new one
     if (markerPositions.Count > 0)
     {
         //pick a random index between min and max index
         int randomIndex = UnityEngine.Random.Range(0, markerPositions.Count - 1);

         //Assign the random marker we found as the active one
         currentMarker = markerPositions[randomIndex];

         //Remove the marker we are using from the list
         markerPositions.RemoveAt(randomIndex);
     }
 }

}

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

2 Replies

  • Sort: 
avatar image
0

Answer by Saryk360 · Jun 11, 2019 at 12:41 AM

Try something like this :


 public List<Vector3> markerPositions = new List<Vector3>();
 public GameObject waypoint;
 public Vector3 currentMarker = new Vector3();
 
 public void OnMarkerComplete()
  {
      //If we have markers remaining in our list we can find a new one
      if (markerPositions.Count > 0)
      {
          //pick a random index between min and max index
          int randomIndex = UnityEngine.Random.Range(0, markerPositions.Count - 1);
          //Assign the random marker we found as the active one
          currentMarker = markerPositions[randomIndex];
          // set the waypoint to the randomly selected marker's position
          waypoint.transform.position = currentMarker;
          //Remove the marker we are using from the list
          markerPositions.RemoveAt(randomIndex);
      }
  }


Comment
Add comment · Show 12 · 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 NoodleCup · Jun 11, 2019 at 12:59 AM 0
Share

Now that I notice it, Its not giving me a change in my current$$anonymous$$arker in the Inspector. So Im guessing its not moving the "Waypoint" to the position because its sitting at 0.0.0? but in that case it should at least move the object to 0,0,0 right? nothing moves at all. no errors.

avatar image Saryk360 NoodleCup · Jun 11, 2019 at 01:01 AM 0
Share

Can I see the declaration for markerPositions ?

avatar image NoodleCup Saryk360 · Jun 11, 2019 at 01:09 AM 0
Share

Sorry, not sure why it got cut off at the top.

public List markerPositions = new List(); I then wen into the Inspector window and manually added Vector3 positions. in the inspector currently its $$anonymous$$arker Positions: Size 3 Element 0: X48,Y-3,Z30 Element1:X17,Y-3,Z30 Element2:X18,Y-3,Z-3

did I provide the right info?

Show more comments
avatar image Saryk360 NoodleCup · Jun 11, 2019 at 01:03 AM 0
Share

Also I edited the declaration of current$$anonymous$$arker.

avatar image NoodleCup Saryk360 · Jun 11, 2019 at 01:19 AM 0
Share

yeah haha sorry let me ask a question a step back. I feel like Im missing a crucial part. I have a vector 3 list at the very top called marker Positions. $$anonymous$$y goal was to take one of the Vector3 positions at random and move the "Destination" object to it. once there, rinse and repeat. I have the vector 3 list to choose from. The choosing at random part doesn't seem to work. Should I post the script in full again? it got cut off at the top for some reason.

Show more comments
avatar image
0

Answer by NoodleCup · Jun 11, 2019 at 01:24 AM

 public class PositionFinder : MonoBehaviour
 {
     //Hold a list of all possible positions - public makes it show in the inspector so your can set them there
     public List<Vector3> markerPositions = new List<Vector3>();
     // markerPositions.Add(new Vector3(48f,-3f,31f));
     public GameObject Waypoint;
 
 
     public Vector3 currentMarker = new Vector3();
 
     public void OnMarkerComplete()
     {
         //If we have markers remaining in our list we can find a new one
         if (markerPositions.Count > 0)
         {
             //pick a random index between min and max index
             int randomIndex = UnityEngine.Random.Range(0, markerPositions.Count - 1);
             //Assign the random marker we found as the active one
             currentMarker = markerPositions[randomIndex];
             // set the waypoint to the randomly selected marker's position
             Waypoint.transform.position = currentMarker;
             //Remove the marker we are using from the list
             markerPositions.RemoveAt(randomIndex);
         }
     }
 }


This is with the "changes" you've suggested to make.

Comment
Add comment · Show 4 · 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 Saryk360 · Jun 11, 2019 at 01:28 AM 0
Share

What triggers On$$anonymous$$arkerComplete() ?

What happens or does not happen now ?

(you should change Waypoint to waypoint also)

avatar image NoodleCup Saryk360 · Jun 11, 2019 at 01:37 AM 0
Share

currently the On$$anonymous$$arkerComplete() when I pick up a pizza. I have a pizza counter with a max of 3. right now its on a pizza object. you drive over it. Pizza counter goes to 1. and uses that function. I assumed it would start a waypoint when player grabs a pizza to be delivered.

looks like I moved it to the Start, was trying to get the script to kicka a new Vector3 for the "current$$anonymous$$arker" since I can see it in the inspector while the game is running. No luck. It might be in the wrong place for all I know.

heres the script for that.

 public class PickUpPizza : $$anonymous$$onoBehaviour
 {
 
 
 
 
 
 
     public void Start()
     {
         GetComponent<PositionFinder>().On$$anonymous$$arkerComplete();
 
 
     }
 
 
 
 
 
 
 
 
     void OnTriggerEnter(Collider other)
     {
         if(other.name == "Car01")
         {
             other.GetComponent<Pizza$$anonymous$$anager>().pizzaCount++;
 
 
             Destroy(gameObject);
         }
     }
 
 }
avatar image Saryk360 NoodleCup · Jun 11, 2019 at 01:57 AM 0
Share

Why are you calling On$$anonymous$$arkerComplete() in Start() ?

Shouldn't it be when the pizza is picked up ?

Show more comments

Follow this Question

Answers Answers and Comments

180 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

Related Questions

GameObject move to each Vector3s in a list 1 Answer

Why transform.localPosition is incorrect on mobile? 1 Answer

i want my enemy spaceship to follow along the way-point after instantiating 0 Answers

Delete duplicates in a list of vectors 1 Answer

How to compare with every list component? 0 Answers


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