diff options
Diffstat (limited to 'JamHelper/Assets/JamTools/FPSControllerVelocity/Scripts/FPSCharacterController.cs')
-rw-r--r-- | JamHelper/Assets/JamTools/FPSControllerVelocity/Scripts/FPSCharacterController.cs | 128 |
1 files changed, 84 insertions, 44 deletions
diff --git a/JamHelper/Assets/JamTools/FPSControllerVelocity/Scripts/FPSCharacterController.cs b/JamHelper/Assets/JamTools/FPSControllerVelocity/Scripts/FPSCharacterController.cs index f995c8e..c51fffc 100644 --- a/JamHelper/Assets/JamTools/FPSControllerVelocity/Scripts/FPSCharacterController.cs +++ b/JamHelper/Assets/JamTools/FPSControllerVelocity/Scripts/FPSCharacterController.cs @@ -28,6 +28,7 @@ namespace JamTools Step = 1 << 12, // ½Å²½
PullTrick = 1 << 13, //
ExtraGravity = 1 << 14, // ¶îÍâÖØÁ¦
+ Crouch = 1 << 15,
} [SerializeField] private CharacterModule m_Modules; @@ -38,14 +39,14 @@ namespace JamTools [SerializeField] private GroundChecker m_GroundChecker;
[SerializeField] private WallChecker m_WallChecker;
+ [SerializeField] private MainCameraFollow m_Camera;
+
#region Modules
[Header("Look Around")]
[SerializeField] private float m_LookSensitive = 1000f;
[Range(0.01f, 1)]
[SerializeField] private float m_LookSmooth = 0.2f;
- [SerializeField] private float m_LookSmoothMultiplier = 100;
- [SerializeField] private bool m_LookSmoothWithTime = true;
private float m_CameraRotation;
private float m_BodyRotation;
@@ -53,12 +54,17 @@ namespace JamTools [SerializeField] private float m_MoveSpeed = 100f;
[Range(0.01f, 1)]
[SerializeField] private float m_MoveSmooth = 0.2f;
- [SerializeField] private float m_MoveSmoothMultiplier = 100;
- [SerializeField] private bool m_MoveSmoothWithTime = true;
private Vector3 m_MoveDirection;
+ private bool m_ReadyMoveAround = false;
[Header("Move In Air")]
[SerializeField] private float m_MoveSpeedInAir = 50f;
+ [SerializeField] private float m_MoveInAirSmooth = 0.2f;
+ private Vector3 m_MoveInAirDirection;
+
+ [Header("Jump")]
+ [SerializeField] private float m_JumpPower = 300f;
+ private bool m_ReadyToJump = false;
[Header("Shot")]
[SerializeField] private Transform m_Muzzle;
@@ -68,7 +74,10 @@ namespace JamTools [Header("WallJump")]
[SerializeField] private float m_WallJumpForce = 1;
[SerializeField] private float m_WallJumpPower = 1000;
+ private bool m_ReadyWallJump = false;
+ [Header("WallRun")]
+ [SerializeField] private float m_WallRunSpeed = 1;
[Header("ExtraGravity")]
[SerializeField] private Vector3 m_ExtraGravity;
@@ -119,16 +128,14 @@ namespace JamTools float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
- float t = m_LookSmoothWithTime ? Time.deltaTime : 1;
-
m_CameraRotation -= mouseY * Time.deltaTime * m_LookSensitive;
m_CameraRotation = Mathf.Clamp(m_CameraRotation, -90, 90);
Quaternion rot = Quaternion.Euler(m_CameraRotation, 0, 0);
- m_Eye.localRotation = Quaternion.Slerp(m_Eye.localRotation, rot, m_LookSmooth * t * m_LookSmoothMultiplier);
+ m_Eye.localRotation = Quaternion.Slerp(m_Eye.localRotation, rot, m_LookSmooth );
m_BodyRotation += mouseX * Time.deltaTime * m_LookSensitive;
rot = Quaternion.Euler(0, m_BodyRotation, 0);
- transform.localRotation = Quaternion.Slerp(transform.localRotation, rot, m_LookSmooth * t * m_LookSmoothMultiplier);
+ transform.localRotation = Quaternion.Slerp(transform.localRotation, rot, m_LookSmooth);
}
void MoveAroundUpdate()
@@ -139,31 +146,33 @@ namespace JamTools if (!m_GroundChecker.isOnGround)
return;
- float moveX = Input.GetAxis("Horizontal");
- float moveZ = Input.GetAxis("Vertical"); + float moveX = Input.GetAxisRaw("Horizontal");
+ float moveZ = Input.GetAxisRaw("Vertical"); Vector3 right = transform.right;
Vector3 forward = transform.forward;
m_MoveDirection = right * moveX + forward * moveZ;
- //if (IsModuleActive(CharacterModule.WalkOnSlope))
- //{
- // if (m_GroundChecker.isOnGround)
- // {
- // RaycastHit hitInfo;
- // if (Physics.Raycast(m_GroundChecker.foot.position, Vector3.down, out hitInfo))
- // {
- // Vector3 normal = hitInfo.normal;
- // m_MoveDirection = Vector3.ProjectOnPlane(m_MoveDirection, normal);
- // GizmosHandle.Instance.DoGizmos(() => {
- // Gizmos.DrawLine(hitInfo.point + new Vector3(0, 0.1f, 0), hitInfo.point + m_MoveDirection);
- // });
- // }
- // }
- //}
+ if (IsModuleActive(CharacterModule.WalkOnSlope))
+ {
+ if (m_GroundChecker.isOnGround)
+ {
+ RaycastHit hitInfo;
+ if (Physics.Raycast(m_GroundChecker.foot.position, Vector3.down, out hitInfo))
+ {
+ Vector3 normal = hitInfo.normal;
+ m_MoveDirection = Vector3.ProjectOnPlane(m_MoveDirection, normal);
+ GizmosHandle.Instance.DoGizmos(() =>
+ {
+ Gizmos.DrawLine(hitInfo.point + new Vector3(0, 0.1f, 0), hitInfo.point + m_MoveDirection);
+ });
+ }
+ }
+ }
m_MoveDirection = m_MoveDirection.normalized;
+
}
void MoveAroundFixedUpdate()
@@ -177,9 +186,7 @@ namespace JamTools float vy = m_Rigidbody.velocity.y;
Vector3 velocity = new Vector3(m_MoveDirection.x * Time.deltaTime * m_MoveSpeed, vy, m_MoveDirection.z * Time.deltaTime * m_MoveSpeed);
- float t = m_MoveSmoothWithTime ? Time.deltaTime : 1;
- m_Rigidbody.velocity = Vector3.Lerp(m_Rigidbody.velocity, velocity, m_MoveSmooth * t * m_MoveSmoothMultiplier);
- //m_Rigidbody.AddForce(velocity * m_MoveSmoothMultiplier, ForceMode.VelocityChange);
+ m_Rigidbody.velocity = Vector3.Lerp(m_Rigidbody.velocity, velocity, m_MoveSmooth);
}
void MoveInAirUpdate()
@@ -190,10 +197,10 @@ namespace JamTools if (m_GroundChecker.isOnGround)
return;
- float moveX = Input.GetAxis("Horizontal");
- float moveZ = Input.GetAxis("Vertical"); + float moveX = Input.GetAxisRaw("Horizontal");
+ float moveZ = Input.GetAxisRaw("Vertical");
- m_MoveDirection = Vector3.ClampMagnitude(transform.right * moveX + transform.forward * moveZ, 1);
+ m_MoveInAirDirection = Vector3.ClampMagnitude(transform.right * moveX + transform.forward * moveZ, 1);
}
void MoveInAirFixedUpdate()
@@ -204,13 +211,13 @@ namespace JamTools if (m_GroundChecker.isOnGround)
return;
- if (m_MoveDirection.magnitude == 0)
+ if (m_MoveInAirDirection.magnitude == 0f)
return;
float vy = m_Rigidbody.velocity.y;
- Vector3 velocity = new Vector3(m_MoveDirection.x * Time.deltaTime * m_MoveSpeedInAir, vy, m_MoveDirection.z * Time.deltaTime * m_MoveSpeedInAir);
+ Vector3 velocity = new Vector3(m_MoveInAirDirection.x * Time.deltaTime * m_MoveSpeedInAir, vy, m_MoveInAirDirection.z * Time.deltaTime * m_MoveSpeedInAir);
- m_Rigidbody.velocity = Vector3.Lerp(m_Rigidbody.velocity, velocity, 0.1f);
+ m_Rigidbody.velocity = Vector3.Lerp(m_Rigidbody.velocity, velocity, m_MoveInAirSmooth);
}
void Jump()
@@ -223,7 +230,16 @@ namespace JamTools if (Input.GetButtonDown("Jump"))
{
- m_Rigidbody.AddForce(Vector3.up * 300, ForceMode.Acceleration);
+ m_ReadyToJump = true;
+ }
+ }
+
+ void JumpFixedUpdate()
+ {
+ if(m_ReadyToJump)
+ {
+ m_ReadyToJump = false;
+ m_Rigidbody.AddForce(Vector3.up * m_JumpPower, ForceMode.Acceleration);
}
}
@@ -234,10 +250,15 @@ namespace JamTools if (Input.GetKeyDown(KeyCode.LeftShift))
{
- m_Rigidbody.AddForce(transform.forward * 5000, ForceMode.Acceleration);
+
}
}
+ void DodgeFixed()
+ {
+
+ }
+
void Shot()
{
if (!IsModuleActive(CharacterModule.Shot))
@@ -284,17 +305,26 @@ namespace JamTools if (Input.GetButtonDown("Jump"))
{
- Vector3 poc;
- if (m_WallChecker.GetCollisionPoint(out poc))
- {
- Vector3 dir = Vector3.ClampMagnitude(transform.position - poc, 1f);
- Vector3 wallJumpDirection = new Vector3(dir.x, 1, dir.z);
- m_Rigidbody.velocity = Vector3.zero;
- m_Rigidbody.AddForce(wallJumpDirection * m_WallJumpPower);
- }
+ m_ReadyWallJump = true;
}
}
+ void WallJumpFixedUpdate()
+ {
+ if(m_ReadyWallJump)
+ {
+ m_ReadyWallJump = false;
+ Vector3 poc;
+ if (m_WallChecker.GetCollisionPoint(out poc))
+ {
+ Vector3 dir = Vector3.ClampMagnitude(transform.position - poc, 1f);
+ Vector3 wallJumpDirection = new Vector3(dir.x, 1, dir.z);
+ m_Rigidbody.velocity = Vector3.zero;
+ m_Rigidbody.AddForce(wallJumpDirection * m_WallJumpPower);
+ }
+ }
+ }
+
void WallRun()
{
if (!IsModuleActive(CharacterModule.WallRun))
@@ -318,6 +348,11 @@ namespace JamTools m_Rigidbody.AddForce(m_ExtraGravity, ForceMode.Acceleration);
}
+ void SetCamera ()
+ {
+ m_Camera.SetCameraPositionAndRotation(m_Eye);
+ }
+
private void Awake()
{
m_Rigidbody = GetComponent<Rigidbody>();
@@ -340,13 +375,18 @@ namespace JamTools Shot();
WallJump();
PullTrick();
+
+ SetCamera();
}
private void FixedUpdate()
{
MoveAroundFixedUpdate();
MoveInAirFixedUpdate();
+ DodgeFixed();
ExtraGravity();
+ JumpFixedUpdate();
+ WallJumpFixedUpdate();
}
private void OnDrawGizmos()
|