自写输入系统
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4129,10 +4129,9 @@ GameObject:
|
|||||||
- component: {fileID: 4874838258577666918}
|
- component: {fileID: 4874838258577666918}
|
||||||
- component: {fileID: 8072573713298176091}
|
- component: {fileID: 8072573713298176091}
|
||||||
- component: {fileID: 4304401782308419094}
|
- component: {fileID: 4304401782308419094}
|
||||||
- component: {fileID: 8570688911153839359}
|
|
||||||
- component: {fileID: 7406758408172975810}
|
|
||||||
- component: {fileID: 1556947158619780183}
|
|
||||||
- component: {fileID: 6041496193769315420}
|
- component: {fileID: 6041496193769315420}
|
||||||
|
- component: {fileID: 3971322442677610698}
|
||||||
|
- component: {fileID: 30265602247666108}
|
||||||
m_Layer: 9
|
m_Layer: 9
|
||||||
m_Name: male
|
m_Name: male
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -4372,7 +4371,7 @@ MonoBehaviour:
|
|||||||
LureTrajectorySimulator: {fileID: 0}
|
LureTrajectorySimulator: {fileID: 0}
|
||||||
Light: {fileID: 4424852676135480966}
|
Light: {fileID: 4424852676135480966}
|
||||||
BackSpine: {fileID: 2935101413777606001}
|
BackSpine: {fileID: 2935101413777606001}
|
||||||
Collider: {fileID: 8570688911153839359}
|
Collider: {fileID: 0}
|
||||||
Rigidbody: {fileID: 3149647016773794308}
|
Rigidbody: {fileID: 3149647016773794308}
|
||||||
--- !u!114 &8072573713298176091
|
--- !u!114 &8072573713298176091
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -4493,139 +4492,6 @@ LineRenderer:
|
|||||||
m_UseWorldSpace: 1
|
m_UseWorldSpace: 1
|
||||||
m_Loop: 0
|
m_Loop: 0
|
||||||
m_ApplyActiveColorSpace: 1
|
m_ApplyActiveColorSpace: 1
|
||||||
--- !u!136 &8570688911153839359
|
|
||||||
CapsuleCollider:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 5559475303044247694}
|
|
||||||
m_Material: {fileID: 0}
|
|
||||||
m_IncludeLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 0
|
|
||||||
m_ExcludeLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 0
|
|
||||||
m_LayerOverridePriority: 0
|
|
||||||
m_IsTrigger: 0
|
|
||||||
m_ProvidesContacts: 0
|
|
||||||
m_Enabled: 1
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Radius: 0.3
|
|
||||||
m_Height: 1.8
|
|
||||||
m_Direction: 1
|
|
||||||
m_Center: {x: 0, y: 0.9, z: 0}
|
|
||||||
--- !u!114 &7406758408172975810
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 5559475303044247694}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 8a5e05c5b0509214d911dd005a610d9a, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
_planeConstraint: 0
|
|
||||||
_rootTransform: {fileID: 0}
|
|
||||||
_rootTransformOffset: {x: 0, y: 0, z: 0}
|
|
||||||
_radius: 0.3
|
|
||||||
_height: 1.8
|
|
||||||
_slopeLimit: 45
|
|
||||||
_stepOffset: 0.45
|
|
||||||
_perchOffset: 0.3
|
|
||||||
_perchAdditionalHeight: 0.4
|
|
||||||
_slopeLimitOverride: 0
|
|
||||||
_useFlatTop: 0
|
|
||||||
_useFlatBaseForGroundChecks: 0
|
|
||||||
_collisionLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 1
|
|
||||||
_triggerInteraction: 1
|
|
||||||
_advanced:
|
|
||||||
minMoveDistance: 0
|
|
||||||
maxMovementIterations: 5
|
|
||||||
maxDepenetrationIterations: 1
|
|
||||||
useFastGeomNormalPath: 0
|
|
||||||
enablePhysicsInteraction: 0
|
|
||||||
allowPushCharacters: 0
|
|
||||||
impartPlatformMovement: 0
|
|
||||||
impartPlatformRotation: 0
|
|
||||||
impartPlatformVelocity: 0
|
|
||||||
_minSlopeLimit: 0.7069833
|
|
||||||
--- !u!114 &1556947158619780183
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 5559475303044247694}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: dcefd1090dc44a539b4fcd30f2adf503, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
_rotationMode: 0
|
|
||||||
_rotationRate: 540
|
|
||||||
_startingMovementMode: 1
|
|
||||||
_maxWalkSpeed: 3
|
|
||||||
_minAnalogWalkSpeed: 0
|
|
||||||
_maxAcceleration: 20
|
|
||||||
_brakingDecelerationWalking: 20
|
|
||||||
_groundFriction: 8
|
|
||||||
_canEverCrouch: 0
|
|
||||||
_crouchedHeight: 1.25
|
|
||||||
_unCrouchedHeight: 2
|
|
||||||
_maxWalkSpeedCrouched: 3
|
|
||||||
_maxFallSpeed: 40
|
|
||||||
_brakingDecelerationFalling: 0
|
|
||||||
_fallingLateralFriction: 0.3
|
|
||||||
_airControl: 0.3
|
|
||||||
_canEverJump: 0
|
|
||||||
_canJumpWhileCrouching: 0
|
|
||||||
_jumpMaxCount: 1
|
|
||||||
_jumpImpulse: 5
|
|
||||||
_jumpMaxHoldTime: 0
|
|
||||||
_jumpMaxPreGroundedTime: 0
|
|
||||||
_jumpMaxPostGroundedTime: 0
|
|
||||||
_maxFlySpeed: 10
|
|
||||||
_brakingDecelerationFlying: 0
|
|
||||||
_flyingFriction: 1
|
|
||||||
_maxSwimSpeed: 3
|
|
||||||
_brakingDecelerationSwimming: 0
|
|
||||||
_swimmingFriction: 0
|
|
||||||
_buoyancy: 1
|
|
||||||
_gravity: {x: 0, y: -9.81, z: 0}
|
|
||||||
_gravityScale: 1
|
|
||||||
_useRootMotion: 0
|
|
||||||
_impartPlatformMovement: 0
|
|
||||||
_impartPlatformRotation: 0
|
|
||||||
_impartPlatformVelocity: 0
|
|
||||||
_enablePhysicsInteraction: 0
|
|
||||||
_applyPushForceToCharacters: 0
|
|
||||||
_applyStandingDownwardForce: 0
|
|
||||||
_mass: 1
|
|
||||||
_pushForceScale: 1
|
|
||||||
_standingDownwardForceScale: 1
|
|
||||||
_camera: {fileID: 0}
|
|
||||||
maxSprintSpeed: 5
|
|
||||||
cameraParent: {fileID: 8796494894830104914}
|
|
||||||
invertLook: 1
|
|
||||||
sensitivity: {x: 0.02, y: 0.02}
|
|
||||||
minPitch: -45
|
|
||||||
maxPitch: 80
|
|
||||||
handMaxAngle: {x: 25, y: -25}
|
|
||||||
nextShowSlotIndex: -1
|
|
||||||
IsSelf: 0
|
|
||||||
lookAtIK: {fileID: 0}
|
|
||||||
aimDistance: 1.5
|
|
||||||
maxUpAngle: 25
|
|
||||||
maxDownAngle: 35
|
|
||||||
interactableLayer:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 0
|
|
||||||
--- !u!114 &6041496193769315420
|
--- !u!114 &6041496193769315420
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -4700,6 +4566,53 @@ MonoBehaviour:
|
|||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
spineTargetOffset: {x: 0, y: 0, z: 0}
|
spineTargetOffset: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!143 &3971322442677610698
|
||||||
|
CharacterController:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5559475303044247694}
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_LayerOverridePriority: 0
|
||||||
|
m_ProvidesContacts: 0
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 3
|
||||||
|
m_Height: 1.8
|
||||||
|
m_Radius: 0.3
|
||||||
|
m_SlopeLimit: 45
|
||||||
|
m_StepOffset: 0.3
|
||||||
|
m_SkinWidth: 0.08
|
||||||
|
m_MinMoveDistance: 0.001
|
||||||
|
m_Center: {x: 0, y: 0.9, z: 0}
|
||||||
|
--- !u!114 &30265602247666108
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 5559475303044247694}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 606ee481d29f49f3a157a642d84c7e74, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
controlMode: 0
|
||||||
|
lookSensitivity: 1
|
||||||
|
lookSmoothing: 0.1
|
||||||
|
moveSpeed: 3
|
||||||
|
jumpHeight: 1
|
||||||
|
gravity: -9.81
|
||||||
|
characterController: {fileID: 3971322442677610698}
|
||||||
|
cameraTransform: {fileID: 5273066534610348271}
|
||||||
|
IsSelf: 0
|
||||||
|
lookAtIK: {fileID: 0}
|
||||||
--- !u!1 &5735120231836046354
|
--- !u!1 &5735120231836046354
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -13,10 +13,21 @@ namespace NBF
|
|||||||
_rigidbody = GetComponent<Rigidbody>();
|
_rigidbody = GetComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LateUpdate()
|
||||||
|
{
|
||||||
|
// BindPosition();
|
||||||
|
}
|
||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
_rigidbody.MovePosition(target.position);
|
BindPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindPosition()
|
||||||
|
{
|
||||||
|
// _rigidbody.MovePosition(target.position);
|
||||||
|
_rigidbody.position = target.position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,334 @@
|
|||||||
|
using System;
|
||||||
|
using RootMotion.FinalIK;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NBF
|
||||||
|
{
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(CharacterController))]
|
||||||
|
public class SmoothFPSController : MonoBehaviour
|
||||||
|
{
|
||||||
|
public enum ControlMode
|
||||||
|
{
|
||||||
|
LocalPlayer, // 本地玩家,接受输入控制
|
||||||
|
NetworkPlayer // 网络玩家,接受数据驱动
|
||||||
|
}
|
||||||
|
|
||||||
|
[Header("Control Settings")] public ControlMode controlMode = ControlMode.LocalPlayer;
|
||||||
|
[Range(0.1f, 10f)] public float lookSensitivity = 2f;
|
||||||
|
[Range(0f, 0.5f)] public float lookSmoothing = 0.1f;
|
||||||
|
[Range(0.1f, 10f)] public float moveSpeed = 5f;
|
||||||
|
public float jumpHeight = 2f;
|
||||||
|
public float gravity = -9.81f;
|
||||||
|
|
||||||
|
[Header("Components")] public CharacterController characterController;
|
||||||
|
public Transform cameraTransform;
|
||||||
|
|
||||||
|
// 物理状态
|
||||||
|
private Vector3 velocity;
|
||||||
|
private bool isGrounded;
|
||||||
|
|
||||||
|
// 视角控制变量
|
||||||
|
private Vector2 currentLookInput;
|
||||||
|
private Vector2 smoothedLookInput;
|
||||||
|
private Vector2 lookVelocity;
|
||||||
|
private float xRotation = 0f;
|
||||||
|
|
||||||
|
// 移动控制变量
|
||||||
|
private Vector2 currentMoveInput;
|
||||||
|
private bool currentJumpInput;
|
||||||
|
|
||||||
|
// 网络同步数据
|
||||||
|
// private Vector3 targetPosition;
|
||||||
|
// private Quaternion targetRotation;
|
||||||
|
private float positionLerpSpeed = 10f;
|
||||||
|
private float rotationLerpSpeed = 5f;
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsSelf;
|
||||||
|
|
||||||
|
private FPlayer _player;
|
||||||
|
public LookAtIK lookAtIK; // 挂在背部上的 LookAtIK 脚本
|
||||||
|
|
||||||
|
private Transform lookTarget; // 实际目标点
|
||||||
|
[Header("限制角度(单位:度)")] public float maxUpAngle = 20f; // 相机抬头最多20°
|
||||||
|
public float maxDownAngle = 40f; // 相机低头最多40°
|
||||||
|
public float aimDistance = 1.5f; // 目标点离相机多远
|
||||||
|
|
||||||
|
[HideInInspector] public int nextShowSlotIndex = -1;
|
||||||
|
|
||||||
|
public LayerMask interactableLayer;
|
||||||
|
|
||||||
|
public Rigidbody physicsBody; // 用于物理同步的Rigidbody
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (characterController == null)
|
||||||
|
characterController = GetComponent<CharacterController>();
|
||||||
|
|
||||||
|
interactableLayer = LayerMask.GetMask("Interactive");
|
||||||
|
physicsBody = GetComponent<Rigidbody>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
InputManager.OnPlayerCanceled += OnPlayerCanceled;
|
||||||
|
InputManager.OnPlayerPerformed += OnPlayerPerformed;
|
||||||
|
|
||||||
|
lookAtIK = GetComponent<LookAtIK>();
|
||||||
|
_player = GetComponent<FPlayer>();
|
||||||
|
|
||||||
|
if (IsSelf)
|
||||||
|
{
|
||||||
|
// camera = BaseCamera.Main;
|
||||||
|
}
|
||||||
|
|
||||||
|
lookTarget = new GameObject("SpineLookTarget").transform;
|
||||||
|
lookTarget.SetParent(_player.transform);
|
||||||
|
|
||||||
|
transform.position = _player.Data.position;
|
||||||
|
transform.rotation = _player.Data.rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
InputManager.OnPlayerCanceled -= OnPlayerCanceled;
|
||||||
|
InputManager.OnPlayerPerformed -= OnPlayerPerformed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (controlMode == ControlMode.LocalPlayer)
|
||||||
|
{
|
||||||
|
UpdateLocalPlayer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateNetworkPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateGear();
|
||||||
|
UpdatePlayerHandView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void GetInputs()
|
||||||
|
{
|
||||||
|
currentMoveInput = InputManager.GetMovementInput();
|
||||||
|
currentLookInput = InputManager.GetLookInput();
|
||||||
|
currentJumpInput = Keyboard.current.spaceKey.wasPressedThisFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void UpdatePlayerHandView()
|
||||||
|
{
|
||||||
|
Vector3 cameraForward = cameraTransform.forward;
|
||||||
|
Vector3 flatForward = Vector3.ProjectOnPlane(cameraForward, Vector3.up).normalized;
|
||||||
|
|
||||||
|
// 获取相机 pitch 角度(负值是上看,正值是下看)
|
||||||
|
float pitchAngle = Vector3.SignedAngle(flatForward, cameraForward, cameraTransform.right);
|
||||||
|
|
||||||
|
// 限制 pitch 角度
|
||||||
|
pitchAngle = Mathf.Clamp(pitchAngle, -maxUpAngle, maxDownAngle);
|
||||||
|
|
||||||
|
// 重新构造限制后的目标方向
|
||||||
|
Quaternion limitedPitch = Quaternion.AngleAxis(pitchAngle, cameraTransform.right);
|
||||||
|
Vector3 limitedDirection = limitedPitch * flatForward;
|
||||||
|
|
||||||
|
// 设置目标点
|
||||||
|
lookTarget.position = cameraTransform.position + limitedDirection * aimDistance;
|
||||||
|
lookAtIK.solver.target = lookTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region 钓组控制
|
||||||
|
|
||||||
|
private void UpdateGear()
|
||||||
|
{
|
||||||
|
if (_player.CanChangeGear())
|
||||||
|
{
|
||||||
|
if (nextShowSlotIndex > 0)
|
||||||
|
{
|
||||||
|
Debug.LogError("切换钓组=========");
|
||||||
|
var data = Fishing.Inst.Datasource;
|
||||||
|
data.SetSelfTestGear(nextShowSlotIndex);
|
||||||
|
nextShowSlotIndex = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 按键输入事件
|
||||||
|
|
||||||
|
private void OnPlayerPerformed(string action)
|
||||||
|
{
|
||||||
|
if (action == "Run")
|
||||||
|
{
|
||||||
|
Sprint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayerCanceled(string action)
|
||||||
|
{
|
||||||
|
if (action == "Run")
|
||||||
|
{
|
||||||
|
StopSprinting();
|
||||||
|
}
|
||||||
|
else if (action.StartsWith("Quick"))
|
||||||
|
{
|
||||||
|
nextShowSlotIndex = int.Parse(action.Substring("Quick".Length));
|
||||||
|
}
|
||||||
|
else if (action == "UseTorch")
|
||||||
|
{
|
||||||
|
_player.Data.openLight = !_player.Data.openLight;
|
||||||
|
}
|
||||||
|
else if (action == "UseTelescope")
|
||||||
|
{
|
||||||
|
_player.Data.openTelescope = !_player.Data.openTelescope;
|
||||||
|
_player.ToggleTelescope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 角色位移和旋转控制
|
||||||
|
|
||||||
|
private bool _isSprinting;
|
||||||
|
private bool _sprintInputPressed;
|
||||||
|
|
||||||
|
[Space(10.0f)] public float maxSprintSpeed = 10.0f;
|
||||||
|
|
||||||
|
private void UpdateNetworkPlayer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateLocalPlayer()
|
||||||
|
{
|
||||||
|
// 获取输入
|
||||||
|
GetInputs();
|
||||||
|
|
||||||
|
// 处理地面检测
|
||||||
|
GroundCheck();
|
||||||
|
|
||||||
|
// 处理移动
|
||||||
|
HandleMovement();
|
||||||
|
|
||||||
|
// 处理视角旋转(现在更加平滑)
|
||||||
|
HandleLookRotation();
|
||||||
|
|
||||||
|
// 处理跳跃
|
||||||
|
// HandleJump();
|
||||||
|
|
||||||
|
// 应用重力
|
||||||
|
ApplyGravity();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void GroundCheck()
|
||||||
|
{
|
||||||
|
isGrounded = characterController.isGrounded;
|
||||||
|
if (isGrounded && velocity.y < 0)
|
||||||
|
{
|
||||||
|
velocity.y = -2f; // 轻微下压确保贴地
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleMovement()
|
||||||
|
{
|
||||||
|
Vector3 move = (transform.right * currentMoveInput.x + transform.forward * currentMoveInput.y) *
|
||||||
|
GetMaxSpeed();
|
||||||
|
characterController.Move(move * Time.deltaTime);
|
||||||
|
// physicsBody.MovePosition(move * Time.deltaTime);
|
||||||
|
// physicsBody.Move(move * Time.deltaTime, transform.rotation);
|
||||||
|
// 手动同步CharacterController和物理位置
|
||||||
|
if (physicsBody != null)
|
||||||
|
{
|
||||||
|
physicsBody.position = transform.position;
|
||||||
|
physicsBody.rotation = transform.rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleLookRotation()
|
||||||
|
{
|
||||||
|
// 应用输入平滑(使用平滑阻尼)
|
||||||
|
smoothedLookInput = Vector2.SmoothDamp(
|
||||||
|
smoothedLookInput,
|
||||||
|
currentLookInput,
|
||||||
|
ref lookVelocity,
|
||||||
|
lookSmoothing);
|
||||||
|
|
||||||
|
// 计算旋转量(应用灵敏度)
|
||||||
|
float lookX = smoothedLookInput.x * lookSensitivity * Time.deltaTime;
|
||||||
|
float lookY = smoothedLookInput.y * lookSensitivity * Time.deltaTime;
|
||||||
|
|
||||||
|
// 水平旋转(左右看)
|
||||||
|
// transform.Rotate(Vector3.up * lookX);
|
||||||
|
|
||||||
|
physicsBody.MoveRotation(physicsBody.rotation * Quaternion.Euler(0, lookX, 0));
|
||||||
|
|
||||||
|
// 垂直旋转(上下看) - 带有角度限制
|
||||||
|
xRotation -= lookY;
|
||||||
|
xRotation = Mathf.Clamp(xRotation, -45f, 80f); // 限制上下视角范围
|
||||||
|
|
||||||
|
// 应用摄像机旋转
|
||||||
|
cameraTransform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleJump()
|
||||||
|
{
|
||||||
|
if (currentJumpInput && isGrounded)
|
||||||
|
{
|
||||||
|
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyGravity()
|
||||||
|
{
|
||||||
|
velocity.y += gravity * Time.deltaTime;
|
||||||
|
characterController.Move(velocity * Time.deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Sprint()
|
||||||
|
{
|
||||||
|
_sprintInputPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request the character to stop sprinting.
|
||||||
|
/// </summary>
|
||||||
|
public void StopSprinting()
|
||||||
|
{
|
||||||
|
_sprintInputPressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanSprint()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
// return IsWalking() && !IsCrouched();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void CheckSprintInput()
|
||||||
|
{
|
||||||
|
if (!_isSprinting && _sprintInputPressed && CanSprint())
|
||||||
|
{
|
||||||
|
_isSprinting = true;
|
||||||
|
}
|
||||||
|
else if (_isSprinting && (!_sprintInputPressed || !CanSprint()))
|
||||||
|
{
|
||||||
|
_isSprinting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetMaxSpeed()
|
||||||
|
{
|
||||||
|
return _isSprinting ? maxSprintSpeed : moveSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 606ee481d29f49f3a157a642d84c7e74
|
||||||
|
timeCreated: 1748348937
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AComponent_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003Fa2_003Fe04a9eef_003FComponent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACursor_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003Fd0_003F709b15ec_003FCursor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACursor_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003Fd0_003F709b15ec_003FCursor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIconAttribute_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F6a_003F44c4467c_003FIconAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIconAttribute_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F6a_003F44c4467c_003FIconAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIMGUIContainer_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4f75f0eb2d14004826911645c6175d61fbe00_003F49_003F22dd7281_003FIMGUIContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIMGUIContainer_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4f75f0eb2d14004826911645c6175d61fbe00_003F49_003F22dd7281_003FIMGUIContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ EditorUserSettings:
|
|||||||
value: 5b08565357035d0c0f5d0a774277071242154029757170697b784e66e6b33060
|
value: 5b08565357035d0c0f5d0a774277071242154029757170697b784e66e6b33060
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-7:
|
RecentlyUsedSceneGuid-7:
|
||||||
value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e
|
value: 0150055704510808545c0a26467506444516197a747874637b7e1860b5b6616c
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-8:
|
RecentlyUsedSceneGuid-8:
|
||||||
value: 0150055704510808545c0a26467506444516197a747874637b7e1860b5b6616c
|
value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-9:
|
RecentlyUsedSceneGuid-9:
|
||||||
value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e
|
value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e
|
||||||
|
|||||||
Reference in New Issue
Block a user