Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 636 characters in body
Source Link

I'm trying to create an infinite flying game where the gameobject (a plane) keeps moving forward and at a particular height throughout the game. I want to be able to
roll and pitch the plane but not move it up/down. I added a rigid body to the plane and selected "y" position constrain. However the plane doesn't stay in the 'y' position but starts move up or down. I just have a script that translates the plane in the z direction. Not sure how to implement the mobile input and keep at the same "y" position throughout.

Update

Here is the code for the plane. Its very basic as I'm not sure how to use the accelerometer:

public class Player : MonoBehaviour {

public float speed = 1.0f;

void Update () {
    float tempx = Input.acceleration.x;
    float tempy = Input.acceleration.y;
    float tempz = Input.acceleration.z;
    transform.Translate(0, 0, 10); // move forward in z 
    transform.Rotate( 0,  tempy * speed, tempz * speed);
}

As for the freezing of the 'y' position, I'm just selecting the y constraint available in the inspector that comes along with the rigidbody.

I'm trying to create an infinite flying game where the gameobject (a plane) keeps moving forward and at a particular height throughout the game. I want to be able to
roll and pitch the plane but not move it up/down. I added a rigid body to the plane and selected "y" position constrain. However the plane doesn't stay in the 'y' position but starts move up or down. I just have a script that translates the plane in the z direction. Not sure how to implement the mobile input and keep at the same "y" position throughout.

I'm trying to create an infinite flying game where the gameobject (a plane) keeps moving forward and at a particular height throughout the game. I want to be able to
roll and pitch the plane but not move it up/down. I added a rigid body to the plane and selected "y" position constrain. However the plane doesn't stay in the 'y' position but starts move up or down. I just have a script that translates the plane in the z direction. Not sure how to implement the mobile input and keep at the same "y" position throughout.

Update

Here is the code for the plane. Its very basic as I'm not sure how to use the accelerometer:

public class Player : MonoBehaviour {

public float speed = 1.0f;

void Update () {
    float tempx = Input.acceleration.x;
    float tempy = Input.acceleration.y;
    float tempz = Input.acceleration.z;
    transform.Translate(0, 0, 10); // move forward in z 
    transform.Rotate( 0,  tempy * speed, tempz * speed);
}

As for the freezing of the 'y' position, I'm just selecting the y constraint available in the inspector that comes along with the rigidbody.

Source Link

Accelerometer input for flying game

I'm trying to create an infinite flying game where the gameobject (a plane) keeps moving forward and at a particular height throughout the game. I want to be able to
roll and pitch the plane but not move it up/down. I added a rigid body to the plane and selected "y" position constrain. However the plane doesn't stay in the 'y' position but starts move up or down. I just have a script that translates the plane in the z direction. Not sure how to implement the mobile input and keep at the same "y" position throughout.