Encountered an issue with my script. I’m not seeing the “nudge” downwards when I add the yThrow to the pitch. It is just adjusting the pitch rotation, but doesn’t “bounch back” when I let go. Is this in a setting somewhere or a change to CrossPlatformInputManager?
Adding to the value does rotate the pitch, but it just doesn’t create the nice bounce effect of letting go at the edges of the screen that I see in the video. Any help would be appreciated.
[Tooltip("In ms^-1")] [SerializeField] float speed = 7f;
[Tooltip("In m")] [SerializeField] float xMaxDistanceFromCenter = 3.8f;
[Tooltip("In m")] [SerializeField] float yMaxDistanceAboveCenter = 2.7f;
[Tooltip("In m")] [SerializeField] float yMaxDistanceBelowCenter = -2.1f;
[SerializeField] float positionPitchFactor = -5f;
[SerializeField] float controlPitchFactor = -20f;
[SerializeField] float positionYawFactor = 5f;
[SerializeField] float controlRollFactor = -20f;
float xThrow, yThrow;
// Update is called once per frame
void Update ()
{
ProcessTranslation();
ProcessRotation();
}
private void ProcessRotation()
{
float pitch = transform.localPosition.y * positionPitchFactor + yThrow;
float yaw = 0f;
float roll = 0f;
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 rawNewXPos = transform.localPosition.x + xOffset;
float rawNewYPos = transform.localPosition.y + yOffset;
float clampedXPos = Mathf.Clamp(rawNewXPos, -xMaxDistanceFromCenter, xMaxDistanceFromCenter);
float clampedYPos = Mathf.Clamp(rawNewYPos, yMaxDistanceBelowCenter, yMaxDistanceAboveCenter);
transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
}