My OOP take on Pitch,Yaw,Roll

I think my “transform.localRotation” variable is a bit messy but i think it’s the cleanest i could come up with.
I hope to get suggestions on maybe cleaner code or how to edit it so it’s more in line with the visual presentation.

    void Update()
    {
        translateShip();
        rotateShip(translateShip());
    }

    private void rotateShip(List<float> position)
    {
        transform.localRotation = Quaternion.Euler(position[1]*-1.5f,position[0]*1.5f,0f);
    }

    private List<float> translateShip()
    {
        float xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
        float yThrow = CrossPlatformInputManager.GetAxis("Vertical");

        float xOffset = xThrow * speed * Time.deltaTime;
        float yOffset = yThrow * speed * Time.deltaTime;

        float rawX = transform.localPosition.x + xOffset;
        float rawY = transform.localPosition.y + yOffset;

        float clampedX = Mathf.Clamp(rawX, -xRange, xRange);
        float clampedY = Mathf.Clamp(rawY, -yRange, yRange);

        transform.localPosition = new Vector3(clampedX, clampedY, transform.localPosition.z);

        return new List<float> {clampedX, clampedY};
    }

Privacy & Terms