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 Abhinash kumar · Mar 21, 2013 at 06:38 AM · randomobjectscreate

random object creation

i m creating a bike race game where i have object cube and it is running fine ,now i want to create random bikes or cars on same track (with some movement) on the way of that object so that user can feel he is actually on the road when i do
right now my cube object in z direction i want my random object to move in same track with same direction(z)

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 robertbu · Mar 21, 2013 at 07:46 AM 0
Share

Take a look at iTween. It will allow you to move object from one point to another. In addition it has limited path features. Take a look at the PutOnPath() and PointOnPath() functions.

avatar image Abhinash kumar · Mar 21, 2013 at 01:01 PM 0
Share

Thanks robertbu checking it now

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Abhinash kumar · Mar 22, 2013 at 09:25 AM

  // VARS FOR RANDOM OBJECT CREATION
 
 // COPY FROM HERE TO END
 
 
 
   var CubePrefab : GameObject;
 
    var AmountOfCubes : int;
 
   var RandomPosx  : int;
 
     var RandomPosy : int;
 
     var RandomPosz : int;
 
  function Start() 
       {
 
          for(var i=0;i<200;i++)
          {      
         if (AmountOfCubes <=200)
            {
 
        RandomPosx = Random.Range (20,100);
        RandomPosy = Random.Range (0,0);
        RandomPosz = Random.Range (0,2042);
        SpawnRandomCube();
           }
        }
 }
    
  
       
      // Move object using accelerometer variables
     var speed = 1;
     var movey=1;
 
 
  function Update () {
 
          var dir : Vector3 = Vector3.zero;
         // we assume that device is held parallel to the ground
         // and Home button is in the right hand
         
         // remap device acceleration axis to game coordinates:
         //  1) XY plane of the device is mapped onto XZ plane 
         //  2) z plane has fixed value 1 which cause it to move in same direction 
         //but user can move in x direction with the phone acceleration sensor   
         dir.x =  Input.acceleration.x;
         dir.z = movey;
         
         // clamp acceleration vector to unit sphere
         if (dir.sqrMagnitude > 1)
             dir.Normalize();
         
         // Make it move 10 meters per second instead of 10 meters per frame...
        //  dir *= Time.deltaTime;
             
         // Move object
         transform.Translate (dir * speed);
         transform.Translate(0, 0, 1);
 }
 
  function SpawnRandomCube()
 {
 
     transform.position = Vector3 (RandomPosx,RandomPosy,RandomPosz);
 
     var RandomCube = Instantiate(CubePrefab,transform.position,transform.rotation);
 
 
    AmountOfCubes = AmountOfCubes + 1;
 
 }
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 sdgd · Mar 22, 2013 at 09:54 AM 1
Share

can you reedit your code so it's readable?

you have 101011 on top there

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

11 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

Related Questions

Creating random objects 2 Answers

Generating objects randomly, only one will Instantiate 0 Answers

Instantiate Random Object at Random Position 1 Answer

Beginner : Random gameobject from array 2 Answers

How to random between 2 objects while spawning? 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