From c4ed57fea8b16cf8dcc7a465a3b63f24fce96502 Mon Sep 17 00:00:00 2001 From: Glence Date: Tue, 1 Nov 2022 13:24:14 +0800 Subject: [PATCH] sprinting works now --- TempScriptsFolder/PlayerController.cs | 53 +++++++++++++++++++++------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/TempScriptsFolder/PlayerController.cs b/TempScriptsFolder/PlayerController.cs index 4e28213d..468ae162 100644 --- a/TempScriptsFolder/PlayerController.cs +++ b/TempScriptsFolder/PlayerController.cs @@ -19,22 +19,26 @@ public class PlayerController : Script private RigidBody rb; private Transform tranform; - public float xAxisMove; - public float zAxisMove; + private float xAxisMove; + private float zAxisMove; + public float drag = 4.0f; private bool isMoveKeyPress = false; public RaccoonStates currentState = RaccoonStates.IDILE; public float maxMoveVel = 2.0f; public float moveForce = 200.0f; public float sprintMultiplier = 1.5f; + private float oldForce; + private float maxOldVel; + private bool sprintIncreaseOnce = false; public float rotationFactorPerFrame = 1.0f; public float jumpForce = 500.0f; /* public float initialJumpForce = 100.0f; public float maxJumpForce = 500.0f; - public float maxJumpTime = 500.0f; + public float maxJumpTime = 500.0f;*/ private bool isJumping = false; - private bool isGrounded = false;*/ + private bool isGrounded = false; public PlayerController(GameObject gameObj) : base(gameObj) { } @@ -43,6 +47,8 @@ public class PlayerController : Script rb = GetComponent(); if (rb == null) Debug.LogError("RigidBody is NULL!"); + else + rb.Drag = drag; tranform = GetComponent(); if(tranform == null) @@ -50,8 +56,6 @@ public class PlayerController : Script tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f); tranform.LocalRotation = Quaternion.Euler(0.0f,0.0f,0.0f); - - RaccoonStates currentState = RaccoonStates.IDILE; } protected override void update() @@ -66,12 +70,17 @@ public class PlayerController : Script //Rotation(); Move(); Sprint(); - //Jump(); + Jump(); - Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString()); + //Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString()); } + protected override void fixedUpdate() + { + } + + private void MoveKey() { if (Input.GetKey(Input.KeyCode.A)) @@ -122,13 +131,27 @@ public class PlayerController : Script private void Sprint() { - if (Input.GetKeyDown(Input.KeyCode.LeftShift) && currentState == RaccoonStates.WALKING && isMoveKeyPress) + if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress) { currentState = RaccoonStates.RUNNING; + if(!sprintIncreaseOnce) + { + sprintIncreaseOnce = true; + oldForce = moveForce; + moveForce = moveForce * sprintMultiplier; + + maxOldVel = maxMoveVel; + maxMoveVel = maxMoveVel * sprintMultiplier; + } } - else if (Input.GetKeyUp(Input.KeyCode.LeftShift) && currentState == RaccoonStates.RUNNING && isMoveKeyPress) + + if (Input.GetKeyUp(Input.KeyCode.LeftShift) && (currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE)) { - currentState = RaccoonStates.WALKING; + if(isMoveKeyPress) + currentState = RaccoonStates.WALKING; + sprintIncreaseOnce = false; + moveForce = oldForce; + maxMoveVel = maxOldVel; } } @@ -140,6 +163,7 @@ public class PlayerController : Script if (Input.GetKeyDown(Input.KeyCode.Space) && rb != null) { currentState = RaccoonStates.INAIR; + isJumping = true; rb.AddForce(new Vector3(0.0f, jumpForce, 0.0f)); } } @@ -166,6 +190,11 @@ public class PlayerController : Script } } - + protected override void onCollisionEnter(CollisionInfo info) + { + Debug.Log($"Collision Enter: {info.GameObject.Name}"); + } + + }