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 Mar 31, 2013 at 11:22 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by Abhinash kumar · Mar 31, 2013 at 10:53 AM · randomobjectsmotion

random object creation and there movement

i have created random object of type cube and when i run it gets created now i want those created objects to have motion in x and z axis,any on eof u know how to do that

Here is my code

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;

}

now i have to move these cubes in z axis and if possible then in z axis.

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 Fattie · Mar 31, 2013 at 11:22 AM 0
Share

suggest you read articles on unityGE$$anonymous$$S.com for many beginner articles on $$anonymous$$OVE$$anonymous$$ENT.

you can use a rigidbody and apply force, or you can animate the object (move it yourself) using Translate or just setting the position

search on here for literally 1000s of answers on it, good luck!

0 Replies

  • Sort: 

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

How to moving objects up and down slowly? 2 Answers

How to make brownian motion of a RigidBody animal AI? 1 Answer

How can I Instantiate an Object from a Randomly Selected Index in an Array of Game Objects? 1 Answer

How do I randomize the movement & rotation of a 2D game object, such that it automatically moves in the direction it faces and not walk diagonally ? 3 Answers

I made this script to instantiate objects, but when the game starts I get this error:IndexOutOfRangeException: Array index is out of range. 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