Other
Gyroscope Controls for FPS
I've made a small fps for android and looking round is done with Gyroscopic control, but when i move I only move forward along the X axis, no matter what direction I'm looking in.
Any suggestions as to how I can fix this?
player movement
CharacterController charControl;
public float Speed = 2f;
float hor; //addition
float ver; //addition
public Joystick joystick; //addition
void Awake () {
charControl = GetComponent<CharacterController>();
}
void Update ()
{
MovePlayer();
}
void MovePlayer()
{
hor = joystick.Horizontal; //addition
ver = joystick.Vertical; //addition
Vector3 moveDirSide = transform.right * hor * Speed;
Vector3 moveDirForward = transform.forward * ver * Speed;
charControl.SimpleMove(moveDirSide);
charControl.SimpleMove(moveDirForward);
}
gyro:
private bool gyroEnabled;
private Gyroscope gyro;
//private GameObject cameraContainer;
private Quaternion rot;
private void Start()
{
//cameraContainer = new GameObject ("Camera Container");
//cameraContainer.transform.position = transform.position;
//transform.SetParent (cameraContainer.transform);
gyroEnabled = EnableGyro();
}
private bool EnableGyro()
{
if (SystemInfo.supportsGyroscope)
{
gyro = Input.gyro;
gyro.enabled = true;
//cameraContainer.transform.rotation = Quaternion.Euler (90f, 90f, 0f);
rot = new Quaternion (0, 0, 1, 0);
return true;
}
return false;
}
private void Update()
{
if (gyroEnabled)
{
transform.localRotation = gyro.attitude * rot;
}
}
}
hello, can you debug.log transform.forward in the playercontroller scipr inside the update and make sure it is changing? also you should be calling simplemove only once per frame consider mixing the horizontal and vertical lines, but this should be your issue. the gyro and the player script are in the exact same gameobject right? not in childs?
Follow this Question
Related Questions
Moving.Rotating a Raycast with Respect to Rotation 1 Answer
Can't move player with this code why?,I cannot move my player with this code why? 0 Answers
Im trying to make a player move 360 degree gyroscopic movement on my phone 0 Answers
How to add random force on x axis for a moving object? 0 Answers
How to make a 2D rigidbody vertically when input is via the gyroscope 0 Answers