Movement showcase with workarounds

So i had the same issue with the input system but didnt look here for advice and tried to solve the issue with some help from discord, i used Vector2.SmoothDamp for the location interpolation and the Quaternion.RotateTowards to smooth the rotation and also implemented a seperate positive and negative pitch values as i found due to my camera angle that the downwards rotation didnt look right so to even it out i needed a more intense downward rotation.

Video of movement

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    [SerializeField] InputAction movement;
    [Range(1,100)] [SerializeField] float xControlSpeed = 30f;
    [Range(1,100)] [SerializeField] float yControlSpeed = 30f;
    [SerializeField] float xRange = 12f;
    [SerializeField] float yRange = 6f;
    [SerializeField] float positivePositionPitchFactor = -2f;
    [SerializeField] float positiveControlPitchFactor = -20f;
    [SerializeField] float negativeControlPitchFactor = -40f;
    [SerializeField] float negativePositionPitchFactor = -2f;
    [SerializeField] float controlRollFactor = -50f;
    [SerializeField] float positionYawFactor = -1f;
    [SerializeField] float smoothInputSpeed = 0.1f;
    [SerializeField] float maxDegrees = 90f;
    Vector2 input;
    Vector2 currentInputVector;
    Vector2 smoothInputVelocity;


    // Start is called before the first frame update
    void Start()
    {
        OnEnable();
    }

    void OnEnable() 
    {
        movement.Enable();    
    }

    void OnDisable() 
    {
        movement.Disable();    
    }

    // Update is called once per frame
    void Update()
    {
        ProcessTranslation();
        ProcessRotation();
    }

    void ProcessRotation()
    {
        float pitchDueToPosition = transform.localPosition.y * positivePositionPitchFactor;
        float pitchDueToControlThrow = currentInputVector.y * positiveControlPitchFactor;

        float negativePitchDueToPosition = transform.localPosition.y * negativePositionPitchFactor;
        float negativePitchDueToControlThrow = currentInputVector.y * negativeControlPitchFactor;

        float rollDuetoControl = currentInputVector.x * controlRollFactor;
        float yawDueToPosition = transform.localPosition.x * positionYawFactor;

        float positivePitch =  pitchDueToPosition + pitchDueToControlThrow;
        float negativePitch =  negativePitchDueToPosition + negativePitchDueToControlThrow;

        float yaw = yawDueToPosition;
        float roll = rollDuetoControl;
        
        if (currentInputVector.y < Mathf.Epsilon) 
        {
            transform.localRotation = Quaternion.RotateTowards(transform.localRotation, Quaternion.Euler(negativePitch, yaw, roll), maxDegrees);
        }
        else
        {
            transform.localRotation = Quaternion.RotateTowards(transform.localRotation, Quaternion.Euler(positivePitch, yaw, roll), maxDegrees);
        }
    }

    void ProcessTranslation()
    {
        Vector2 input = movement.ReadValue<Vector2>();
        currentInputVector = Vector2.SmoothDamp(currentInputVector, input, ref smoothInputVelocity, smoothInputSpeed);

        float xOffset = currentInputVector.x * Time.deltaTime * xControlSpeed;
        float rawXPos = transform.localPosition.x + xOffset;
        float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);

        float yOffset = currentInputVector.y * Time.deltaTime * yControlSpeed;
        float rawYPos = transform.localPosition.y + yOffset;
        float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);

        transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
    }
}

Privacy & Terms