My Movements are working just fine with the Keyboard or Gamepad ARROWS, zero issues. But there is an issue with the Gamepad Joystick. Player does not start moving at all if I put Joystick right in between X and Z axis (diagonally).But Player will move if I put Joystick forward/backward or left/right. So if I want to start moving diagonally from idle with Joystick I can’t…
private void Awake() // fields
{
RB_PlayerParent = GetComponent<Rigidbody>();
TR_PlayerParent = this.transform;
GO_MainCamera = GameObject.Find("MainCamera");
TR_MainCamera = GO_MainCamera.transform;
}
void _InputControls() //Called in Update()
{
_Zaxis_Input = Input.GetAxis("Vertical");
_Xaxis_Input = Input.GetAxis("Horizontal");
_MovementDirection = new Vector3(_Xaxis_Input, 0, _Zaxis_Input);
}
void _MovePosition() //called in FixedUpdate()
{
// Without this If statement the player will turn and move to camera angle automatically
if (_MovementDirection.magnitude == 0) return;
//Rotation
float _playerAngle = Mathf.Atan2(_Xaxis_Input, _Zaxis_Input) * Mathf.Rad2Deg + TR_MainCamera.eulerAngles.y;
float _smoothAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, _playerAngle, ref _CurrentVelocity, _RotationSpeed);
RB_PlayerParent.MoveRotation(Quaternion.Euler(0f, _smoothAngle, 0f));
//Actual Movement
Vector3 _cameraToMovement = Quaternion.Euler(0f, TR_MainCamera.eulerAngles.y, 0f) * _MovementDirection;
RB_PlayerParent.AddForce(_cameraToMovement * _PlayerSpeed * Time.deltaTime, ForceMode.VelocityChange);
}