using UnityEngine;
using System.Collections;
public class Accelerometer : MonoBehaviour {
public Vector3 positionplayer;
// Update is called once per frame
void Update ()
{
transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
transform.Rotate (0,0,0);
}
}
i have attached this script to the player,every thing is working fine but when it hits an obstacle it starts bouncing..but it doesn't bounce on the ground(only when the wall is hit)
i have made the ground using plane and four walls using cube
For player have added a collider, rigid body and set rigidbody to gravity with mass 1
for the walls i have added box collider and just a rigidbody
this in my new code
using UnityEngine;
using System.Collections;
public class Accelerometer : MonoBehaviour {
public Vector3 positionplayer;
Rigidbody b;
public float speed = 10.0f;
private Quaternion localRotation;
// Use this for initialization
void Start () {
localRotation = transform.rotation;
}
// Update is called once per frame
void Update ()
{
float curSpeed = Time.deltaTime * speed;
//transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
transform.position += (transform.right * Input.acceleration.x) * curSpeed;
transform.position += (transform.forward * -Input.acceleration.z) * curSpeed;
//transform.Rotate (Input.acceleration.x,0,0);
localRotation.z += -Input.acceleration.z * curSpeed;
localRotation.z += Input.acceleration.z * curSpeed;
//transform.rotation = localRotation;
print (transform.position);
}
}