#Thread
1 messages · Page 1 of 1 (latest)
private void FixedUpdate()
{
Move();
if (OutsideForce.sqrMagnitude > Mathf.Epsilon) OutsideForce = Vector3.Lerp(OutsideForce, Vector3.zero, forceDissipationRate * Time.fixedDeltaTime);
_currentSpeed = Mathf.Lerp(_currentSpeed, _targetSpeed, _crouchLerpSpeed * Time.fixedDeltaTime);
}
void Move()
{
Vector3 _inputs;
Vector3 _targetVector;
_inputs = new Vector3( _moveInput.ReadValue<Vector2>().x, 0, _moveInput.ReadValue<Vector2>().y );
_isMoving = Mathf.Abs(_inputs.magnitude) > Mathf.Epsilon;
if (_isMoving && canMove)
{
_targetVector = Quaternion.AngleAxis(transform.eulerAngles.y, transform.up) * (_inputs * _acceleration * accelMult * _currentMaxSpeed * Time.fixedDeltaTime);
Debug.Log(_inputs);
// Shoots a ray downwards to get the angle of the slope
if (Physics.Raycast(transform.position, Vector3.down, out hit, 0.3f, detectionMask, QueryTriggerInteraction.Ignore))
{
_targetVector = Vector3.ProjectOnPlane(_targetVector, hit.normal);
}
_rigid.velocity += _targetVector;
CheckSpeed();
}
else
{
_rigid.velocity -= Velocity() * _deceleration * accelMult * Time.fixedDeltaTime;
}
//used to reduce gravity while the player isn't moving
float funny = Mathf.Clamp01(MathF.Sqrt(_rigid.velocity.magnitude / _currentMaxSpeed));
_rigid.velocity += Physics.gravity * Time.deltaTime * (_isGrounded ? funny : 1);
//apply outside force
if (OutsideForce.sqrMagnitude > 1) _rigid.velocity += OutsideForce;
}
public class MouseLook : MonoBehaviour
{
[Header("Mouse Settings")]
public static Vector2 Sensitivity;
private PlayerInput _inputMap;// m_mouseAction;
private InputAction _mouseAction;
public Transform _cameraTransform; // This script controls the rotation of the Camera Transform child
internal Vector2 Rotation = Vector2.zero;
private void Start()
{
Rotation.x = transform.rotation.eulerAngles.y;
Sensitivity = new Vector2(3.5f, 4);
_inputMap = GetComponent<PlayerInput>();
_mouseAction = _inputMap.currentActionMap.FindAction("Look", true);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
//if (!GamestateManager.isPaused && !_dead)
RotateCamera();
}
const int mult = 20;
public void RotateCamera()
{
Rotation.x += _mouseAction.ReadValue<Vector2>().x * Sensitivity.x / mult;
Rotation.y += _mouseAction.ReadValue<Vector2>().y * Sensitivity.y / mult;
Rotation.y = Mathf.Clamp(Rotation.y, -90f, 90f);
transform.localRotation = Quaternion.Euler(0, Rotation.x, 0);
_cameraTransform.localRotation = Quaternion.Euler(-Rotation.y,0,0);
}
} ```
Timescale is set to 0.1 in the video. While moving, the player movement, which the camera is parented to, seems to be completely smooth. When rotating my camera, you can see what I assume is the fixed physics timestep.