mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(Controllers): Use Input.mousePosition instead of GetAxisRaw
This commit is contained in:
parent
04bb95311b
commit
c475ef95f0
@ -469,6 +469,7 @@ MonoBehaviour:
|
||||
_mouseInputX: 0
|
||||
_mouseSensitivity: 0
|
||||
_groundState: 0
|
||||
_mousePosition: {x: 0, y: 0}
|
||||
_direction: {x: 0, y: 0, z: 0}
|
||||
_velocity: {x: 0, y: 0, z: 0}
|
||||
_controllerUI: {fileID: 0}
|
||||
|
@ -469,6 +469,7 @@ MonoBehaviour:
|
||||
_mouseInputX: 0
|
||||
_mouseSensitivity: 0
|
||||
_groundState: 0
|
||||
_mousePosition: {x: 0, y: 0}
|
||||
_direction: {x: 0, y: 0, z: 0}
|
||||
_velocity: {x: 0, y: 0, z: 0}
|
||||
_controllerUI: {fileID: 0}
|
||||
|
@ -487,6 +487,7 @@ MonoBehaviour:
|
||||
_mouseInputX: 0
|
||||
_mouseSensitivity: 0
|
||||
_groundState: 0
|
||||
_mousePosition: {x: 0, y: 0}
|
||||
_direction: {x: 0, y: 0, z: 0}
|
||||
_velocity: {x: 0, y: 0, z: 0}
|
||||
_controllerUI: {fileID: 0}
|
||||
|
@ -487,6 +487,7 @@ MonoBehaviour:
|
||||
_mouseInputX: 0
|
||||
_mouseSensitivity: 0
|
||||
_groundState: 0
|
||||
_mousePosition: {x: 0, y: 0}
|
||||
_direction: {x: 0, y: 0, z: 0}
|
||||
_velocity: {x: 0, y: 0, z: 0}
|
||||
_controllerUI: {fileID: 0}
|
||||
|
@ -260,6 +260,7 @@ MonoBehaviour:
|
||||
_mouseSensitivity: 10
|
||||
_lastShotTime: 0
|
||||
_turretUI: {fileID: 0}
|
||||
_mousePosition: {x: 0, y: 0}
|
||||
turretNetworkTransform: {fileID: 8662002890669114756}
|
||||
barrelNetworkTransform: {fileID: 4362334322449175123}
|
||||
--- !u!114 &8662002890669114756
|
||||
|
@ -260,6 +260,7 @@ MonoBehaviour:
|
||||
_mouseSensitivity: 10
|
||||
_lastShotTime: 0
|
||||
_turretUI: {fileID: 0}
|
||||
_mousePosition: {x: 0, y: 0}
|
||||
turretNetworkTransform: {fileID: 8518206564796711397}
|
||||
barrelNetworkTransform: {fileID: 470423508858832317}
|
||||
--- !u!114 &8518206564796711397
|
||||
|
@ -161,6 +161,7 @@ public struct RuntimeData
|
||||
[ReadOnly, SerializeField, Range(-1f, 1f)] float _mouseInputX;
|
||||
[ReadOnly, SerializeField, Range(0, 30f)] float _mouseSensitivity;
|
||||
[ReadOnly, SerializeField] GroundState _groundState;
|
||||
[ReadOnly, SerializeField] Vector2 _mousePosition;
|
||||
[ReadOnly, SerializeField] Vector3 _direction;
|
||||
[ReadOnly, SerializeField] Vector3Int _velocity;
|
||||
[ReadOnly, SerializeField] GameObject _controllerUI;
|
||||
@ -239,6 +240,12 @@ public GroundState groundState
|
||||
internal set => _groundState = value;
|
||||
}
|
||||
|
||||
public Vector2 mousePosition
|
||||
{
|
||||
get => _mousePosition;
|
||||
internal set => _mousePosition = value;
|
||||
}
|
||||
|
||||
public Vector3 direction
|
||||
{
|
||||
get => _direction;
|
||||
@ -313,6 +320,7 @@ public override void OnStartAuthority()
|
||||
// Calculate DPI-aware sensitivity
|
||||
float dpiScale = (Screen.dpi > 0) ? (Screen.dpi / BASE_DPI) : 1f;
|
||||
runtimeData.mouseSensitivity = turnAcceleration * dpiScale;
|
||||
runtimeData.mousePosition = Input.mousePosition;
|
||||
|
||||
SetCursor(controlOptions.HasFlag(ControlOptions.MouseSteer));
|
||||
|
||||
@ -392,7 +400,7 @@ void Update()
|
||||
|
||||
void SetCursor(bool locked)
|
||||
{
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
//Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
|
||||
@ -436,8 +444,13 @@ void HandleTurning(float deltaTime)
|
||||
|
||||
void HandleMouseSteer(float deltaTime)
|
||||
{
|
||||
// Get mouse position, calculate delta
|
||||
Vector2 currentMousePosition = Input.mousePosition;
|
||||
Vector2 mouseDelta = currentMousePosition - runtimeData.mousePosition;
|
||||
runtimeData.mousePosition = currentMousePosition;
|
||||
|
||||
// Accumulate mouse input over time
|
||||
runtimeData.mouseInputX += Input.GetAxisRaw("Mouse X") * runtimeData.mouseSensitivity;
|
||||
runtimeData.mouseInputX += mouseDelta.x * runtimeData.mouseSensitivity;
|
||||
|
||||
// Clamp the accumulator to simulate key press behavior
|
||||
runtimeData.mouseInputX = Mathf.Clamp(runtimeData.mouseInputX, -1f, 1f);
|
||||
|
@ -125,6 +125,7 @@ public struct RuntimeData
|
||||
[ReadOnly, SerializeField, Range(-1f, 1f)] float _mouseInputX;
|
||||
[ReadOnly, SerializeField, Range(0, 30f)] float _mouseSensitivity;
|
||||
[ReadOnly, SerializeField] GroundState _groundState;
|
||||
[ReadOnly, SerializeField] Vector2 _mousePosition;
|
||||
[ReadOnly, SerializeField] Vector3 _direction;
|
||||
[ReadOnly, SerializeField] Vector3Int _velocity;
|
||||
[ReadOnly, SerializeField] GameObject _controllerUI;
|
||||
@ -185,6 +186,12 @@ public GroundState groundState
|
||||
internal set => _groundState = value;
|
||||
}
|
||||
|
||||
public Vector2 mousePosition
|
||||
{
|
||||
get => _mousePosition;
|
||||
internal set => _mousePosition = value;
|
||||
}
|
||||
|
||||
public Vector3 direction
|
||||
{
|
||||
get => _direction;
|
||||
@ -260,6 +267,7 @@ public override void OnStartAuthority()
|
||||
// Calculate DPI-aware sensitivity
|
||||
float dpiScale = (Screen.dpi > 0) ? (Screen.dpi / BASE_DPI) : 1f;
|
||||
runtimeData.mouseSensitivity = turnAcceleration * dpiScale;
|
||||
runtimeData.mousePosition = Input.mousePosition;
|
||||
|
||||
SetCursor(controlOptions.HasFlag(ControlOptions.MouseSteer));
|
||||
|
||||
@ -327,7 +335,7 @@ void Update()
|
||||
|
||||
void SetCursor(bool locked)
|
||||
{
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
//Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
|
||||
@ -372,8 +380,13 @@ void HandleTurning(float deltaTime)
|
||||
|
||||
void HandleMouseSteer(float deltaTime)
|
||||
{
|
||||
// Get mouse position, calculate delta
|
||||
Vector2 currentMousePosition = Input.mousePosition;
|
||||
Vector2 mouseDelta = currentMousePosition - runtimeData.mousePosition;
|
||||
runtimeData.mousePosition = currentMousePosition;
|
||||
|
||||
// Accumulate mouse input over time
|
||||
runtimeData.mouseInputX += Input.GetAxisRaw("Mouse X") * runtimeData.mouseSensitivity;
|
||||
runtimeData.mouseInputX += mouseDelta.x * runtimeData.mouseSensitivity;
|
||||
|
||||
// Clamp the accumulator to simulate key press behavior
|
||||
runtimeData.mouseInputX = Mathf.Clamp(runtimeData.mouseInputX, -1f, 1f);
|
||||
@ -387,6 +400,7 @@ void HandleMouseSteer(float deltaTime)
|
||||
// Apply rotation
|
||||
transform.Rotate(0f, runtimeData.turnSpeed * deltaTime, 0f);
|
||||
|
||||
// Decay mouse input
|
||||
runtimeData.mouseInputX = Mathf.MoveTowards(runtimeData.mouseInputX, 0f, runtimeData.mouseSensitivity * deltaTime);
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,7 @@ public struct RuntimeData
|
||||
[ReadOnly, SerializeField, Range(-1f, 1f)] float _mouseInputX;
|
||||
[ReadOnly, SerializeField, Range(0, 30f)] float _mouseSensitivity;
|
||||
[ReadOnly, SerializeField] GroundState _groundState;
|
||||
[ReadOnly, SerializeField] Vector2 _mousePosition;
|
||||
[ReadOnly, SerializeField] Vector3 _direction;
|
||||
[ReadOnly, SerializeField] Vector3Int _velocity;
|
||||
[ReadOnly, SerializeField] GameObject _controllerUI;
|
||||
@ -185,6 +186,12 @@ public GroundState groundState
|
||||
internal set => _groundState = value;
|
||||
}
|
||||
|
||||
public Vector2 mousePosition
|
||||
{
|
||||
get => _mousePosition;
|
||||
internal set => _mousePosition = value;
|
||||
}
|
||||
|
||||
public Vector3 direction
|
||||
{
|
||||
get => _direction;
|
||||
@ -264,6 +271,7 @@ public override void OnStartAuthority()
|
||||
// Calculate DPI-aware sensitivity
|
||||
float dpiScale = (Screen.dpi > 0) ? (Screen.dpi / BASE_DPI) : 1f;
|
||||
runtimeData.mouseSensitivity = turnAcceleration * dpiScale;
|
||||
runtimeData.mousePosition = Input.mousePosition;
|
||||
|
||||
SetCursor(controlOptions.HasFlag(ControlOptions.MouseSteer));
|
||||
|
||||
@ -364,7 +372,7 @@ void HandleOptions()
|
||||
|
||||
void SetCursor(bool locked)
|
||||
{
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
//Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
|
||||
@ -390,8 +398,13 @@ void HandleTurning(float deltaTime)
|
||||
|
||||
void HandleMouseSteer(float deltaTime)
|
||||
{
|
||||
// Get mouse position, calculate delta
|
||||
Vector2 currentMousePosition = Input.mousePosition;
|
||||
Vector2 mouseDelta = currentMousePosition - runtimeData.mousePosition;
|
||||
runtimeData.mousePosition = currentMousePosition;
|
||||
|
||||
// Accumulate mouse input over time
|
||||
runtimeData.mouseInputX += Input.GetAxisRaw("Mouse X") * runtimeData.mouseSensitivity;
|
||||
runtimeData.mouseInputX += mouseDelta.x * runtimeData.mouseSensitivity;
|
||||
|
||||
// Clamp the accumulator to simulate key press behavior
|
||||
runtimeData.mouseInputX = Mathf.Clamp(runtimeData.mouseInputX, -1f, 1f);
|
||||
|
@ -127,6 +127,7 @@ public struct RuntimeData
|
||||
[ReadOnly, SerializeField, Range(0, 30f)] float _mouseSensitivity;
|
||||
[ReadOnly, SerializeField] double _lastShotTime;
|
||||
[ReadOnly, SerializeField] GameObject _turretUI;
|
||||
[ReadOnly, SerializeField] Vector2 _mousePosition;
|
||||
|
||||
#region Properties
|
||||
|
||||
@ -172,6 +173,12 @@ public GameObject turretUI
|
||||
internal set => _turretUI = value;
|
||||
}
|
||||
|
||||
public Vector2 mousePosition
|
||||
{
|
||||
get => _mousePosition;
|
||||
internal set => _mousePosition = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -277,6 +284,7 @@ public override void OnStartAuthority()
|
||||
// Calculate DPI-aware sensitivity
|
||||
float dpiScale = (Screen.dpi > 0) ? (Screen.dpi / BASE_DPI) : 1f;
|
||||
runtimeData.mouseSensitivity = turretAcceleration * dpiScale;
|
||||
runtimeData.mousePosition = Input.mousePosition;
|
||||
|
||||
SetCursor(controlOptions.HasFlag(ControlOptions.MouseLock));
|
||||
this.enabled = true;
|
||||
@ -316,7 +324,7 @@ void OnPlayerColorChanged(Color32 _, Color32 newColor)
|
||||
|
||||
void SetCursor(bool locked)
|
||||
{
|
||||
Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
//Cursor.lockState = locked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !locked;
|
||||
}
|
||||
|
||||
@ -356,8 +364,13 @@ void HandleTurning(float deltaTime)
|
||||
|
||||
void HandleMouseTurret(float deltaTime)
|
||||
{
|
||||
// Get mouse position, calculate delta
|
||||
Vector2 currentMousePosition = Input.mousePosition;
|
||||
Vector2 mouseDelta = currentMousePosition - runtimeData.mousePosition;
|
||||
runtimeData.mousePosition = currentMousePosition;
|
||||
|
||||
// Accumulate mouse input over time
|
||||
runtimeData.mouseInputX += Input.GetAxisRaw("Mouse X") * runtimeData.mouseSensitivity;
|
||||
runtimeData.mouseInputX += mouseDelta.x * runtimeData.mouseSensitivity;
|
||||
|
||||
// Clamp the accumulator to simulate key press behavior
|
||||
runtimeData.mouseInputX = Mathf.Clamp(runtimeData.mouseInputX, -1f, 1f);
|
||||
@ -371,6 +384,7 @@ void HandleMouseTurret(float deltaTime)
|
||||
// Apply rotation
|
||||
turret.Rotate(0f, runtimeData.turretSpeed * deltaTime, 0f);
|
||||
|
||||
// Decay mouse input
|
||||
runtimeData.mouseInputX = Mathf.MoveTowards(runtimeData.mouseInputX, 0f, runtimeData.mouseSensitivity * deltaTime);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user