initial room transitioning
This commit is contained in:
@@ -7,6 +7,7 @@ public class PlayerController : MonoBehaviour
|
||||
public GameObject DougBody;
|
||||
public Shovel Shovel;
|
||||
public float walkSpeed;
|
||||
public float gravity = 10;
|
||||
|
||||
float digTime = 0.9f;
|
||||
float digTimestamp = 0;
|
||||
@@ -16,10 +17,7 @@ public class PlayerController : MonoBehaviour
|
||||
private CharacterController characterController;
|
||||
private CameraController cameraController;
|
||||
private Vector3 moveDir;
|
||||
private float gravity = 10;
|
||||
|
||||
private float camTargetRotation = 0;
|
||||
private bool isCamRotating = false;
|
||||
private bool hasControl = true; // set this to false if we want to stop reading player inputs
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
@@ -31,24 +29,28 @@ void Start()
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!isDigging)
|
||||
if (hasControl)
|
||||
{
|
||||
RotatePlayerTowardMouse();
|
||||
TryInteract();
|
||||
if (!isDigging)
|
||||
{
|
||||
RotatePlayerTowardMouse();
|
||||
TryInteract();
|
||||
}
|
||||
|
||||
Walk();
|
||||
DigDetector();
|
||||
|
||||
// TODO: This is just for testing, remove or clean up if used
|
||||
if (Input.GetKeyDown(KeyCode.LeftShift))
|
||||
{
|
||||
cameraController.RotateCam();
|
||||
}
|
||||
}
|
||||
|
||||
Walk();
|
||||
DigDetector();
|
||||
|
||||
// TODO: This is just for testing, remove or clean up if used
|
||||
if (Input.GetKeyDown(KeyCode.LeftShift))
|
||||
{
|
||||
RotateCam();
|
||||
}
|
||||
|
||||
HandleCamRotation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle movement
|
||||
/// </summary>
|
||||
void Walk()
|
||||
{
|
||||
float verticalMovement = 0;
|
||||
@@ -81,6 +83,9 @@ void Walk()
|
||||
characterController.Move(moveDir * Time.deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect input for digging (will eventually be tool agnostic)
|
||||
/// </summary>
|
||||
void DigDetector()
|
||||
{
|
||||
if (!isDigging)
|
||||
@@ -99,8 +104,11 @@ void DigDetector()
|
||||
isDigging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Face character graphic toward mouse
|
||||
/// </summary>
|
||||
void RotatePlayerTowardMouse()
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
@@ -118,6 +126,9 @@ void RotatePlayerTowardMouse()
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to interact by detecting nearest interactable
|
||||
/// </summary>
|
||||
void TryInteract()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) && nearestInteractable != null)
|
||||
@@ -151,33 +162,19 @@ private void OnTriggerExit(Collider other)
|
||||
}
|
||||
}
|
||||
|
||||
void RotateCam()
|
||||
/// <summary>
|
||||
/// Sets the character's "hasControl" bool. All input is ignored when false
|
||||
/// </summary>
|
||||
public void SetCharacterControl(bool hasControl)
|
||||
{
|
||||
if (!isCamRotating)
|
||||
{
|
||||
float currentY = cameraController.playerCamHome.transform.rotation.eulerAngles.y;
|
||||
camTargetRotation = currentY + 90f;
|
||||
isCamRotating = true;
|
||||
}
|
||||
this.hasControl = hasControl;
|
||||
}
|
||||
|
||||
void HandleCamRotation()
|
||||
/// <summary>
|
||||
/// Gets the character's "hasControl" bool. All input is ignored when false
|
||||
/// </summary>
|
||||
public bool GetCharacterHasControl()
|
||||
{
|
||||
float currentY = cameraController.playerCamHome.transform.rotation.eulerAngles.y;
|
||||
|
||||
float step = 200 * Time.deltaTime;
|
||||
|
||||
float newY = Mathf.MoveTowardsAngle(currentY, camTargetRotation, step);
|
||||
|
||||
cameraController.playerCamHome.RotateAround(
|
||||
transform.position,
|
||||
Vector3.up,
|
||||
newY - currentY
|
||||
);
|
||||
|
||||
if (Mathf.Abs(Mathf.DeltaAngle(newY, camTargetRotation)) < 0.01f)
|
||||
{
|
||||
isCamRotating = false;
|
||||
}
|
||||
return hasControl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user