fix: PlayerMovement now works fine
update: Player no longer has Rigidbody add: added UserSettings to .gitignore .
This commit is contained in:
@@ -496,7 +496,6 @@ GameObject:
|
||||
- component: {fileID: 2060574367}
|
||||
- component: {fileID: 2060574366}
|
||||
- component: {fileID: 2060574365}
|
||||
- component: {fileID: 2060574364}
|
||||
- component: {fileID: 2060574363}
|
||||
- component: {fileID: 2060574362}
|
||||
- component: {fileID: 2060574368}
|
||||
@@ -523,7 +522,7 @@ MonoBehaviour:
|
||||
sprintSpeedMultiplier: 2
|
||||
crouchSpeedMultiplier: 0.5
|
||||
crouchHeightMultiplier: 0.5
|
||||
jumpForce: 1
|
||||
jumpForce: 5
|
||||
gravityMultiplier: 1
|
||||
isCrouching: 0
|
||||
--- !u!143 &2060574363
|
||||
@@ -551,33 +550,6 @@ CharacterController:
|
||||
m_SkinWidth: 0.08
|
||||
m_MinMoveDistance: 0.001
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!54 &2060574364
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2060574361}
|
||||
serializedVersion: 4
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_CenterOfMass: {x: 0, y: 0, z: 0}
|
||||
m_InertiaTensor: {x: 1, y: 1, z: 1}
|
||||
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ImplicitCom: 1
|
||||
m_ImplicitTensor: 1
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 0
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_CollisionDetection: 0
|
||||
--- !u!23 &2060574365
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -9,21 +9,20 @@ public class PlayerMovement : MonoBehaviour
|
||||
public float jumpForce = 1f;
|
||||
public float gravityMultiplier = 1f;
|
||||
|
||||
Rigidbody rb;
|
||||
CharacterController characterController;
|
||||
[SerializeField] bool isCrouching = false;
|
||||
Vector3 charControllerCenter;
|
||||
Vector3 gravityVelocity;
|
||||
bool grounded;
|
||||
|
||||
void Start() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
characterController = GetComponent<CharacterController>();
|
||||
charControllerCenter = characterController.center;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
grounded = characterController.isGrounded;
|
||||
HandleCrouching();
|
||||
HandleJumping();
|
||||
HandleMovement();
|
||||
HandleJumping();
|
||||
DoGravity();
|
||||
}
|
||||
|
||||
@@ -37,13 +36,13 @@ public class PlayerMovement : MonoBehaviour
|
||||
characterController.height /= crouchHeightMultiplier;
|
||||
characterController.center -= Vector3.down * (characterController.height * (1 - crouchHeightMultiplier)) / 2;
|
||||
}
|
||||
if (characterController.isGrounded) rb.AddForce(Vector3.up * (characterController.height / 5), ForceMode.VelocityChange);
|
||||
// if (characterController.isGrounded) rb.AddForce(Vector3.up * (characterController.height / 5), ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleJumping() {
|
||||
if (Input.GetKeyDown(KeyCode.Space) && characterController.isGrounded) {
|
||||
rb.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange);
|
||||
if (Input.GetKeyDown(KeyCode.Space) && grounded) {
|
||||
gravityVelocity = Vector3.up * (jumpForce * gravityMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +58,9 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
|
||||
void DoGravity() {
|
||||
characterController.Move(rb.linearVelocity * (gravityMultiplier * Time.deltaTime));
|
||||
if (characterController.isGrounded) rb.linearVelocity *= 0.2f;
|
||||
if (grounded && gravityVelocity.y < 0) gravityVelocity = Vector3.down * 0.5f;
|
||||
gravityVelocity += Physics.gravity * Time.deltaTime;
|
||||
characterController.Move(gravityVelocity * (Time.deltaTime * gravityMultiplier));
|
||||
}
|
||||
|
||||
void OnControllerColliderHit(ControllerColliderHit hit) {
|
||||
|
||||
Reference in New Issue
Block a user