Hey. i want to do a tilting platform thing using the gyroscope of my phone. at the moment it looks like this using WASD keys:
https://dribbble.com/shots/2205018-iMaze-Tilting-Behavior
what i want to do now is that the platform gets tilted (horizontal and vertical input)based on how you tilt your ipad or phone.
the code looks like this at the moment:
using UnityEngine;
using System.Collections;
public class TiltPlatform : MonoBehaviour {
public bool smoothMotion = true;
//This is how quickly we MoveTowards the input axis.
public float smoothSpeed = 1f;
//The maximum we want our input axis to reach. Setting this lower will rotate the platform less, and higher will be more.
public float multiplier = 0.1f;
//Variables, don't edit these.
private float hSmooth = 0f;
private float vSmooth = 0f;
private float h;
private float v;
void Update () {
//Get Vertical and Horizontal axis from Input
h = Input.GetAxis("Horizontal")*multiplier;
v = Input.GetAxis("Vertical")*multiplier;
}
void FixedUpdate() {
hSmooth = Mathf.MoveTowards(hSmooth,h,smoothSpeed* Time.deltaTime);
vSmooth = Mathf.MoveTowards(vSmooth,v,smoothSpeed * Time.deltaTime);
//Rotate to match the new axis using EulerAngles.
if(!smoothMotion){
transform.rotation = Quaternion.EulerAngles(new Vector3(h,0f,v));
}else{
transform.rotation = Quaternion.EulerAngles(new Vector3(hSmooth,0f,vSmooth));
}
}
}