PlayerController and PickAndThrow #167
|
@ -10,7 +10,7 @@ public class PlayerController : Script
|
|||
IDILE,
|
||||
WALKING,
|
||||
RUNNING,
|
||||
INAIR,
|
||||
JUMP,
|
||||
FALLING,
|
||||
HOLDING,
|
||||
CAUGHT,
|
||||
|
@ -19,26 +19,47 @@ public class PlayerController : Script
|
|||
|
||||
private RigidBody rb;
|
||||
private Transform tranform;
|
||||
private int xAxisMove;
|
||||
private int zAxisMove;
|
||||
|
||||
//to be remove
|
||||
public float drag = 2.0f;
|
||||
private bool isMoveKeyPress = false;
|
||||
[SerializeField]
|
||||
[Tooltip("The current state fo the raccoon")]
|
||||
public RaccoonStates currentState = RaccoonStates.IDILE;
|
||||
|
||||
//Movement variables============================================================
|
||||
[SerializeField]
|
||||
[Tooltip("Max vel for walking")]
|
||||
public float maxMoveVel = 2.0f;
|
||||
[SerializeField]
|
||||
[Tooltip("how much force is apply for walking")]
|
||||
public float moveForce = 50.0f;
|
||||
[SerializeField]
|
||||
[Tooltip("increase the moveForce and maxMoveVel by its amt")]
|
||||
public float sprintMultiplier = 2.0f;
|
||||
|
||||
private float oldForce;
|
||||
private float maxOldVel;
|
||||
private bool sprintIncreaseOnce = false;
|
||||
private int xAxisMove;
|
||||
private int zAxisMove;
|
||||
private bool isMoveKeyPress = false;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("curr not working")]
|
||||
public float rotationFactorPerFrame = 1.0f;
|
||||
|
||||
|
||||
public float initialJumpVel;
|
||||
public float maxJumpHeight = 1.0f;
|
||||
public float maxJumpTime = 0.5f;
|
||||
private bool isJumping = false;
|
||||
public bool isGrounded = true;
|
||||
//Jumping vars==================================================================
|
||||
[SerializeField]
|
||||
[Tooltip("max height of the jump")]
|
||||
public float maxJumpHeight = 4.0f;
|
||||
[SerializeField]
|
||||
[Tooltip("max amt of time it will take for the jump")]
|
||||
public float maxJumpTime = 0.75f;
|
||||
[SerializeField]
|
||||
[Tooltip("increase gravity when falling")]
|
||||
public float fallMultipler = 2.0f;
|
||||
private float initialJumpVel;
|
||||
private bool isGrounded = true;
|
||||
private float gravity = -9.8f;
|
||||
private float groundGravity = -0.5f;
|
||||
|
||||
|
@ -80,7 +101,7 @@ public class PlayerController : Script
|
|||
MoveKey();
|
||||
|
||||
|
||||
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()
|
||||
|
@ -111,10 +132,10 @@ public class PlayerController : Script
|
|||
|
||||
isMoveKeyPress = xAxisMove != 0 || zAxisMove != 0;
|
||||
|
||||
if(isMoveKeyPress && currentState != RaccoonStates.RUNNING)
|
||||
if(isMoveKeyPress && currentState != RaccoonStates.RUNNING && isGrounded)
|
||||
currentState = RaccoonStates.WALKING;
|
||||
|
||||
if (!isMoveKeyPress)
|
||||
if (!isMoveKeyPress && isGrounded)
|
||||
currentState = RaccoonStates.IDILE;
|
||||
}
|
||||
|
||||
|
@ -144,7 +165,7 @@ public class PlayerController : Script
|
|||
|
||||
private void Sprint()
|
||||
{
|
||||
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress)
|
||||
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded)
|
||||
{
|
||||
currentState = RaccoonStates.RUNNING;
|
||||
if(!sprintIncreaseOnce)
|
||||
|
@ -158,7 +179,7 @@ public class PlayerController : Script
|
|||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift) && (currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE))
|
||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift))
|
||||
{
|
||||
if(isMoveKeyPress)
|
||||
currentState = RaccoonStates.WALKING;
|
||||
|
@ -173,23 +194,17 @@ public class PlayerController : Script
|
|||
{
|
||||
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE)
|
||||
{
|
||||
if (Input.GetKeyDown(Input.KeyCode.Space)&& isGrounded && rb != null)
|
||||
if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null)
|
||||
{
|
||||
isJumping = true;
|
||||
currentState = RaccoonStates.JUMP;
|
||||
Vector3 v = rb.LinearVelocity;
|
||||
v.y = initialJumpVel;
|
||||
v.y = initialJumpVel * 0.5f;
|
||||
rb.LinearVelocity = v;
|
||||
}
|
||||
}
|
||||
|
||||
if (rb != null)
|
||||
{
|
||||
if (rb.LinearVelocity.y > 0 && isJumping)
|
||||
currentState = RaccoonStates.INAIR;
|
||||
else if(rb.LinearVelocity.y < 0 && isJumping)
|
||||
if(rb != null && !isGrounded && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space)))
|
||||
currentState = RaccoonStates.FALLING;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Rotation()
|
||||
|
@ -215,7 +230,7 @@ public class PlayerController : Script
|
|||
if (rb != null)
|
||||
{
|
||||
//check player vel.y if its close to zero its on the ground
|
||||
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f, 0.1f))
|
||||
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f))
|
||||
isGrounded = true;
|
||||
else
|
||||
isGrounded = false;
|
||||
|
@ -224,8 +239,20 @@ public class PlayerController : Script
|
|||
|
||||
if (isGrounded)
|
||||
v.y = groundGravity;
|
||||
else if (currentState == RaccoonStates.FALLING)
|
||||
{
|
||||
float prevYVel = v.y;
|
||||
float newYVel = v.y + (gravity * fallMultipler * (float)Time.DeltaTime);
|
||||
float nextYVel = (prevYVel + newYVel) * 0.5f;
|
||||
v.y = nextYVel;
|
||||
}
|
||||
else
|
||||
v.y += gravity * (float)Time.DeltaTime;
|
||||
{
|
||||
float prevYVel = v.y;
|
||||
float newYVel = v.y + (gravity * (float)Time.DeltaTime);
|
||||
float nextYVel = (prevYVel + newYVel) * 0.5f;
|
||||
v.y = nextYVel;
|
||||
}
|
||||
|
||||
rb.LinearVelocity = v;
|
||||
|
||||
|
|
Loading…
Reference in New Issue