Steer by turning the phone
Turn a phone held sideways into a steering value from -1 to 1.
Video: Steer by turning the phone (2:33)
GameObject → PadPlay → PadPlay Setup
Add the PhoneWheel script below to your car
Add a Center button to the layout (Role = Recenter)
using PadPlay;
using UnityEngine;
public class PhoneWheel : MonoBehaviour
{
[SerializeField] PadPlayHost host;
[SerializeField] int playerSlot = 0; // P1
[SerializeField] float fullLockDegrees = 90f; // turn this far = full lock
public float Steer { get; private set; } // -1 left .. 1 right
void Update()
{
PadPlayPad pad = host.GetPad(playerSlot);
if (pad == null || !pad.IsConnected)
return;
// After a Full recenter the pose the player holds is "straight".
Vector3 up = pad.attitude.ReadValue() * Vector3.up;
Vector3 flat = Vector3.ProjectOnPlane(up, Vector3.forward);
float angle = Vector3.SignedAngle(Vector3.up, flat, Vector3.forward);
Steer = Mathf.Clamp(-angle / fullLockDegrees, -1f, 1f); // clockwise = right
}
}Hold the phone like a wheel and press Center. Turning right makes Steer positive.