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 /
This question was closed May 02, 2014 at 01:54 AM by robertbu for the following reason:

Duplicate Question/Multiple Issues

avatar image
0
Question by ProToCooL · May 02, 2014 at 01:40 AM · movementpositionvector3

How do i make an object move unpredictably?

I'm trying to get an object to move from one position to another and as soon as it reaches that position, another position to get randomly picked and for the object to move to THAT one till it gets clicked on. If there's a solution for this, preferably in C# that'd be lovely. Thank you in advance.

This is what i got so far:

 using UnityEngine; 
 using System.Collections;
     
 public class MoveGreg : MonoBehaviour {
     
         public float movementSpeed;
 
      public Vector3 direction;
 
      void Update(){
          while (true) {
              direction = new Vector3(random(-10,10),random (-4.59,4.56),0);
                         movementSpeed = random(0.1,0.8);
              transform.Translate(direction * movementSpeed * Time.deltaTime);
          }
      }
     
         public float random(double min, double max)
      {
             return Random.Range ((float)min, (float)max);     
         } 
 }
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 robertbu · May 02, 2014 at 01:54 AM 0
Share

Unity Answers is for answering single specific technical questions. Your question has multiple issues:

  1. Finding a random position: you don't say what kind of position. It could be in a square area, a cubic area, within a sphere. All of these have been covered on UA. Exa$$anonymous$$e the various functions and the sample source for Unity's Random class.

  2. $$anonymous$$ove a block over time: Your code is not the right way to move an object over time. $$anonymous$$oving object over time is in the top ten list of most asked questions. There are 1000's of answers on UA. Search out these answers. For your purposes, take a look at Vector3.$$anonymous$$oveTowards() and Vector3.Lerp() in the Unity reference.

  3. Detect a click on an object: There's Raycasting() and On$$anonymous$$ouseDown() to solve this problem. Raycasting is also in the UA top ten. You will find 1000's of answers.

Break your problem into these three parts. Write test apps to solve each one independently, then put the three together. If you get stuck, we welcome your new question with a single, specific issue.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Moving an Object - The right way. 2D 1 Answer

Instantiated object isnt moving 1 Answer

Problem with a motion script 0 Answers

Sum Of Two Motions? 0 Answers

Check if 2 objects positions are close enough 2 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