sprinting works now
This commit is contained in:
parent
d51a87ed36
commit
c4ed57fea8
|
@ -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<RigidBody>();
|
||||
if (rb == null)
|
||||
Debug.LogError("RigidBody is NULL!");
|
||||
else
|
||||
rb.Drag = drag;
|
||||
|
||||
tranform = GetComponent<Transform>();
|
||||
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;
|
||||
}
|
||||
else if (Input.GetKeyUp(Input.KeyCode.LeftShift) && currentState == RaccoonStates.RUNNING && isMoveKeyPress)
|
||||
if(!sprintIncreaseOnce)
|
||||
{
|
||||
sprintIncreaseOnce = true;
|
||||
oldForce = moveForce;
|
||||
moveForce = moveForce * sprintMultiplier;
|
||||
|
||||
maxOldVel = maxMoveVel;
|
||||
maxMoveVel = maxMoveVel * sprintMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift) && (currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE))
|
||||
{
|
||||
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}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue