Advertisement
Guest User

Control Script

a guest
Jul 19th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var speed = 10.0;
  4.  
  5. function Update () {
  6.     var dir : Vector3 = Vector3.zero;
  7.  
  8.     // we assume that device is held parallel to the ground
  9.     // and Home button is in the right hand
  10.        
  11.     // remap device acceleration axis to game coordinates:
  12.     //  1) XY plane of the device is mapped onto XZ plane
  13.     //  2) rotated 90 degrees around Y axis
  14.     dir.x = Input.acceleration.x;
  15.     dir.z = Input.acceleration.y;
  16.        
  17.     // clamp acceleration vector to unit sphere
  18.     if (dir.sqrMagnitude > 1)
  19.         dir.Normalize();
  20.        
  21.     // Make it move 10 meters per second instead of 10 meters per frame...
  22.     dir *= Time.deltaTime;
  23.            
  24.     // Move object
  25.     transform.Translate (dir * speed);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement