I’m fooling around with a PS4 controller and am throwing together a simple twin stick shooter.
I want the camera to move towards the direction the player is looking, but for whatever reason the thing ends up jiggling ever so slightly and I can not for the life of me understand why.
I attempted to add a threshold that it needed to pass before the camera would move, but it just seems to completely fail to do anything and I am straight up dumbfounded why.
Here’s my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestPlayer : MonoBehaviour
{
public float movementSpeed;
public float lookRange;
public float lookSmooth;
Vector3 movementDirection;
Vector3 lookDirection;
Vector3 cameraStartPosition;
CharacterController myController;
public Transform myCamera;
public Transform target;
// Start is called before the first frame update
void Start()
{
myController = gameObject.GetComponent<CharacterController>();
cameraStartPosition = myCamera.localPosition;
}
// Update is called once per frame
void Update()
{
movementDirection = new Vector3(Input.GetAxis("P1LHor"), 0, Input.GetAxis("P1LVert") * -1);
myController.Move(movementDirection * movementSpeed * Time.deltaTime);
Vector3 lastLookDirection = lookDirection;
lookDirection = new Vector3(Input.GetAxis("P1RHor"), 0, Input.GetAxis("P1RVert") * -1);
lookDirection = lookDirection * lookRange;
lookDirection += cameraStartPosition;
if (Vector3.Distance(lookDirection, lastLookDirection) > lookSmooth){
myCamera.localPosition = lookDirection;
}
}
}
The smoothing function works, but it causes the camera to jump around.