PlayerController and PickAndThrow #167

Merged
glencelow merged 21 commits from PlayerController into main 2022-11-02 17:40:51 +08:00
1 changed files with 101 additions and 8 deletions
Showing only changes of commit 0ffd596734 - Show all commits

View File

@ -1,13 +1,37 @@
using SHADE;
using System;
//in air controls?
public class PlayerController : Script
{
public enum RaccoonStates
{
IDILE,
WALKING,
RUNNING,
INAIR,
FALLING,
HOLDING,
CAUGHT,
TOTAL
}
private RigidBody rb;
public float xAxisMove;
public float zAxisMove;
public float force = 800.0f;
private float xAxisMove;
private float zAxisMove;
private RaccoonStates currentState = RaccoonStates.IDILE;
public float maxMoveVel = 2.0f;
public float moveForce = 200.0f;
public float sprintMultiplier = 1.5f;
public float jumpForce = 500.0f;
public float initialJumpForce = 100.0f;
public float maxJumpForce = 500.0f;
public float maxJumpTime = 500.0f;
private bool isJumping = false;
private bool isGrounded = false;
public PlayerController(GameObject gameObj) : base(gameObj) { }
@ -18,14 +42,22 @@ public class PlayerController : Script
{
Debug.LogError("RigidBody is NULL!");
}
RaccoonStates currentState = RaccoonStates.IDILE;
}
protected override void update()
{
Move();
currentState = RaccoonStates.IDILE;
//float x = xAxisMove * force * (float)Time.DeltaTime;
//Debug.Log(x.ToString());
Move();
Sprint();
Jump();
if (rb != null && currentState == RaccoonStates.IDILE)
rb.LinearVelocity = new Vector3(0.0f, 0.0f, 0.0f);
Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
}
private void Move()
@ -45,8 +77,69 @@ public class PlayerController : Script
else
zAxisMove = 0;
if (rb != null)
rb.AddForce(new Vector3(xAxisMove * force * (float)Time.DeltaTime, 0.0f, zAxisMove * force * (float)Time.DeltaTime));
if((Input.GetKey(Input.KeyCode.A) || Input.GetKey(Input.KeyCode.D) || Input.GetKey(Input.KeyCode.W) || Input.GetKey(Input.KeyCode.S)) && currentState != RaccoonStates.RUNNING)
currentState = RaccoonStates.WALKING;
if (rb != null && currentState == RaccoonStates.WALKING)
{
if (rb.LinearVelocity.x <= maxMoveVel)
rb.AddForce(new Vector3(moveForce * xAxisMove * (float)Time.DeltaTime, 0.0f, 0.0f));
else
{
Vector3 v = rb.LinearVelocity;
v.x = maxMoveVel;
rb.LinearVelocity = v;
}
if (rb.LinearVelocity.z <= maxMoveVel)
rb.AddForce(new Vector3(0.0f, 0.0f, moveForce * zAxisMove * (float)Time.DeltaTime));
else
{
Vector3 v = rb.LinearVelocity;
v.z = maxMoveVel;
rb.LinearVelocity = v;
}
}
}
private void Sprint()
{
//left shift not working for now and chang eto getkey down
if (Input.GetKey(Input.KeyCode.RightShift))
{
if (currentState == RaccoonStates.WALKING && rb != null)
{
currentState = RaccoonStates.RUNNING;
rb.LinearVelocity *= sprintMultiplier;
}
}
if (Input.GetKeyUp(Input.KeyCode.RightShift))
{
if (currentState == RaccoonStates.RUNNING && rb != null)
{
currentState = RaccoonStates.WALKING;
rb.LinearVelocity /= sprintMultiplier;
}
}
}
//press and hold jump
private void Jump()
{
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE)
{
if (Input.GetKeyDown(Input.KeyCode.Space) && rb != null)
{
currentState = RaccoonStates.INAIR;
rb.AddForce(new Vector3(0.0f, jumpForce, 0.0f));
}
}
//collision check when grounded
}
}