Sunday, 1 March 2015

Unity3D TUTORIAL: 22 Random Object Movement

Unity3D TUTORIAL: 22 Random Object Movement









THIS IS Java script: GOOD 4 2D GAMES AND 3D GAMES ! 
----------------------------------------­­­­­­­----------------------------------­-­-­-­-­-­-­------



DIRECT DOWNLOAD HERE


----------------------------------------­­­­­------------------------------------­-­-­-­-­-

THIS IS BACKUP  IN TEXT FORM  TUTORIAL 22
1. Create New java and name it : RandomMovement

2. Copy & Past this text and save java :
----------------------------------------­­­­­------------------------------------­-­-­-­-­-


 var target:Vector3;
 var timer:float;
 var sec:int;
 function Start () {
  target = ResetTarget();
  sec=ResetSec();
 }
 
 function Update () {
 timer+=Time.deltaTime;
 if(timer>sec){
 target=ResetTarget();
 sec=ResetSec();
 }
 transform.Translate(target*10*Time.deltaTime);
 }
 function ResetTarget():Vector3{
     return Vector3(Random.Range(-2.0,2.0),Random.Range(-2.0,2.0),Random.Range(-2.0,2.0));
 }
 function ResetSec():int{
     timer =0;
     return Random.Range(1,3);
 }


----------------------------------------­­­­­------------------------------------­-­-­-­-­-





----------------------------------------­­­­­------------------------------------­-­-­-­-­-

THIS IS BACKUP  IN TEXT FORM  TUTORIAL 22
1. Create New java and name it : RandomRotate

2. Copy & Past this text and save java :
----------------------------------------­­­­­------------------------------------­-­-­-­-­-


#pragma strict
private var rotTarget:Quaternion;
var rotateEverySecond:float = 1;
private var lerpCounter:float;
private var rotCache:Quaternion;

function Start () {
randomRot ();
InvokeRepeating("randomRot", 0,rotateEverySecond);
}

function Update(){
transform.rotation = Quaternion.Lerp(transform.rotation, rotTarget, lerpCounter*Time.deltaTime);
lerpCounter++;
}

function randomRot () {
 
rotTarget = Random.rotation;
rotCache = transform.rotation;
lerpCounter = 0;
}



----------------------------------------­­­­­------------------------------------­-­-­-­-­-

















0 comments:

Post a Comment