- Home /
Question by
alb917 · Nov 05, 2012 at 08:52 PM ·
iosiphonetiltconstant force
iOS Tilt input and constant force
I'm working on an iOS game similar to Temple Run. I'm working on the player controls and come across a problem. I had added a constant force to move the player forward, and this had worked, until I added the tiltInput script for iOS. The constant force then works when testing the game on my desktop, but when I connect my iPhone, and test the game on there, there is no constant force but the tilt input works.
Here is the code for the runner:
using UnityEngine;
public class Runner : MonoBehaviour {
void Update () {
transform.Translate(5f * Time.deltaTime, 0f, 0f);
}
}
and here is the tilt input script, that Unity gives us:
using UnityEngine;
using System.Collections;
public class tiltInput : MonoBehaviour {
public Vector3 tiltVector = Vector3.zero;
public Transform cube;
public int speed = 1;
void Update () {
tiltVector = Input.acceleration;
cube.Translate(-Vector3.back * speed * tiltVector.y);
if(tiltVector.y > 0){
Debug.Log ("Cube is traveling left! X Vector is: " + tiltVector);
}
if (tiltVector.y < 0){
Debug.Log ("Cube is traveling right! X Vector is: " +tiltVector);
}
}
}
Can anybody help at all?
Comment