Hi all,
making progress but I’m stumped again.
My gryocopter refuses to roll. I have the pitch and yaw working fine, but it flat out refuses to roll. Can someone look over my script and tell me where I went wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class gyroplayer : MonoBehaviour
{
[Tooltip(“In meters per second”)][SerializeField] float speed = 20f;
[Tooltip(“In meters”)] [SerializeField] float xRange = 10f;
[Tooltip(“In meters”)] [SerializeField] float yRange = 5f;
[SerializeField] float positionPitchFactor = 2f;
[SerializeField] float controlPitchFactor = -20f;
[SerializeField] float positionYawFactor = -1.5f;
[SerializeField] float controlRollFactor = -5f;
float xThrow, yThrow;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
processTranslation();
processRotation();
}
private void processRotation()
{
float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
float pitchDueToControlThrow = yThrow * controlPitchFactor;
float pitch = pitchDueToPosition + pitchDueToControlThrow;
float yaw = transform.localPosition.x * positionYawFactor;
float roll = xThrow * controlRollFactor;
transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}
private void processTranslation()
{
float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
float yThrow = CrossPlatformInputManager.GetAxis("Vertical");
float xOffset = xThrow * speed * Time.deltaTime;
float yOffset = yThrow * speed * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);
float rawYPos = transform.localPosition.y + yOffset;
float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);
transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
}
}