- Home /
Question by
Kenneth Andersen · Dec 11, 2011 at 10:21 AM ·
c#androidaccelerationtilt
C# Tilting object with acceleration on andoid
Hello, I'm making a simple topdown shooter with a spaceship for android.
I can move this ship up and down the X and Y axis by tilting my phone. The code bit for that part looks like this:
void MovePlayer()
{
Vector3 dir = Vector3.zero;
dir.x = -Input.acceleration.y;
dir.y = Input.acceleration.x;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed,Space.World);
}
What I want to do is to make the spaceship tilt a little to the right when it goes to the right, and a little to the left when it goes to the left. But I'm not sure how to do that, because I don't know what to check up on to see if the plane is accelerating to the left or right.
Thanks in advance :)
Comment
Your answer
Follow this Question
Related Questions
C# Move object by tilting on android device. 5 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Ball maze android issues 1 Answer
GameObject dosen't move 2 Answers