- Home /
 
               Question by 
               ryisnelly · Feb 07, 2017 at 02:16 AM · 
                androidaccelerometer  
              
 
              android accelerometer rotation
 hello,
hello, 
i am making a game that uses a table tennis bat that bounces a ball , the bat moves using the accelerometer, i can make the bat move along the x and y axis, i would like the bat to rotate slightly when table tennis bat nears the edge of the screen, any idea who i would accomplish this?
thanks
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class clamp : MonoBehaviour {
     public float xaxis;
     public float yaxis;
     public float zaxis;
     public float rotspeed;
     public float speed = 100.0f;
 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
         var pos = transform.position;
         pos.x =  Mathf.Clamp(transform.position.x, -3.0f, 3.0f);
         transform.position = pos;
 
         var pos2 = transform.position;
         pos2.y = Mathf.Clamp (transform.position.y, -5.5f, 2.0f);
         transform.position = pos2;
 
         var pos3 = transform.position;
         pos3.z = Mathf.Clamp (transform.position.z, 6.5f, 6.88f);
         transform.position = pos3;
 
 
         xaxis = Input.acceleration.x;
         yaxis = Input.acceleration.y;
         zaxis = Input.acceleration.z;
         transform.Translate (xaxis, 0, yaxis);
         rotspeed = yaxis * 10;
         transform.Rotate(0,rotspeed,0);
 }
 }
 
 
                 
                game.png 
                (17.3 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                