Original, higher quality video (My Google Drive)
Sorry if I mess something up with this post, I don’t post to the internet often and this is my first post to the site.
edit: apparently i messed something up with google drive. i’m not too familiar with using that either. when i move up, the nose of the ship moves down. and when i move down, the nose of the ship also moves down.
As you can see, my vertical movement is off, I cannot seem to fix the odd rotation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Player : MonoBehaviour {
[SerializeField] float xSpeed;
[SerializeField] float xClampRange;
[SerializeField] float ySpeed;
[SerializeField] float yClampRange;
[SerializeField] float positionPitchFactor = -5f;
[SerializeField] float controlPitchFactor = -5f;
[SerializeField] float positionYawFactor = 5f;
[SerializeField] float controlRollFactor = -20f;
float xThrow;
float yThrow;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
xYMovement();
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);
print(pitchDueToControlThrow);
}
private void xYMovement()
{
xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
float xOffset = xThrow * xSpeed * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float clampedXPos = Mathf.Clamp(rawXPos, -xClampRange, xClampRange);
yThrow = CrossPlatformInputManager.GetAxis("Vertical");
float yOffset = yThrow * ySpeed * Time.deltaTime;
float rawYPos = transform.localPosition.y + yOffset;
float clampedYPos = Mathf.Clamp(rawYPos, -yClampRange, yClampRange);
transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
}
}