add auto-walk from the door
This commit is contained in:
@@ -67,9 +67,11 @@ public void EnterSceneDoor(string scene, int door)
|
||||
private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
|
||||
{
|
||||
isTransitioningScenes = true;
|
||||
playerController.SetCharacterControl(false);
|
||||
|
||||
// Fade to black
|
||||
float fadeDuration = 0.2f;
|
||||
float fadeDuration = 0.2f; // how long to fade to/from black
|
||||
float moveDuration = 0.4f; // how long to auto walk into room from the door
|
||||
float fadeTime = 0;
|
||||
Color blackScreenColor = Color.black;
|
||||
|
||||
@@ -95,10 +97,10 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
|
||||
// Make sure screen is black in new scene
|
||||
blackScreen.color = blackScreenColor;
|
||||
|
||||
SceneDoor door = GameSceneManager.Instance.GetDoorWithId(doorId);
|
||||
|
||||
if (playerController != null && GameSceneManager.Instance != null)
|
||||
{
|
||||
SceneDoor door = GameSceneManager.Instance.GetDoorWithId(doorId);
|
||||
|
||||
if (door != null)
|
||||
{
|
||||
playerController.CharacterControllerMove(door.gameObject.transform.position - playerController.transform.position);
|
||||
@@ -112,11 +114,23 @@ private IEnumerator EnterSceneDoorCoroutine(string scene, int doorId)
|
||||
blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration);
|
||||
blackScreen.color = blackScreenColor;
|
||||
fadeTime += Time.deltaTime;
|
||||
|
||||
playerController.WalkInDirection((door.WalkDirection.position - playerController.transform.position).normalized);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// move character a little more
|
||||
while (fadeTime < moveDuration)
|
||||
{
|
||||
playerController.WalkInDirection((door.WalkDirection.position - playerController.transform.position).normalized);
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
fadeTime = 0;
|
||||
|
||||
isTransitioningScenes = false;
|
||||
playerController.SetCharacterControl(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -109,6 +109,29 @@ public void CharacterControllerMove(Vector3 movement)
|
||||
characterController.Move(movement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto-walk the character in the specified direction. Uses character's walk
|
||||
/// speed and camera rotation (per-frame)
|
||||
/// </summary>
|
||||
public void WalkInDirection(Vector3 direction)
|
||||
{
|
||||
Vector3 forwardDir = direction;
|
||||
forwardDir.y = 0; // don't move on the y axis
|
||||
|
||||
if (cameraController != null)
|
||||
{
|
||||
// re-matrix the rotation direction so movement is consistent no matter what
|
||||
// the camera rotation is
|
||||
|
||||
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
||||
forwardDir = matrix.MultiplyPoint3x4(forwardDir);
|
||||
}
|
||||
|
||||
forwardDir *= walkSpeed;
|
||||
|
||||
characterController.Move(forwardDir * Time.deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect input for digging (will eventually be tool agnostic)
|
||||
/// </summary>
|
||||
|
||||
@@ -4,6 +4,10 @@ public class RoomDoor : Interactable
|
||||
{
|
||||
public RoomDoor linkedDoor;
|
||||
public bool requiresInteraction; // Do we need to press a button to enter?
|
||||
|
||||
// transform that the character should walk towards when entering the room
|
||||
// through this door
|
||||
public Transform WalkDirection;
|
||||
TeleportHandler teleportHandler;
|
||||
|
||||
// not required and only plays if interaction is required
|
||||
|
||||
@@ -11,6 +11,10 @@ public class SceneDoor : Interactable
|
||||
// Which door does this lead to in the scene this door takes us to?
|
||||
public int IdOfCorrespondingDoor = 0;
|
||||
|
||||
// transform that the character should walk towards when entering the room
|
||||
// through this door
|
||||
public Transform WalkDirection;
|
||||
|
||||
public override void Interact()
|
||||
{
|
||||
// Do nothing
|
||||
|
||||
@@ -28,14 +28,12 @@ public void EnterRoom(RoomDoor door)
|
||||
/// </summary>
|
||||
IEnumerator EnterRoomCoroutine(RoomDoor door)
|
||||
{
|
||||
float fadeDuration = 0.2f;
|
||||
float fadeDuration = 0.2f; // how long to fade to/from black
|
||||
float moveDuration = 0.4f; // how long to auto walk into room from the door
|
||||
float fadeTime = 0;
|
||||
Color blackScreenColor = Color.black;
|
||||
|
||||
playerController.SetCharacterControl(false);
|
||||
// Don't use the Y axis to look at the door
|
||||
Vector3 positionToLookAt = new Vector3(door.transform.position.x, playerController.DougBody.transform.position.y, door.transform.position.z);
|
||||
playerController.DougBody.transform.LookAt(positionToLookAt);
|
||||
|
||||
// Play door open animation
|
||||
if (door.requiresInteraction)
|
||||
@@ -57,6 +55,15 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
|
||||
{
|
||||
blackScreenColor.a = Mathf.Lerp(1, 0, fadeTime / fadeDuration);
|
||||
blackScreenObject.color = blackScreenColor;
|
||||
playerController.WalkInDirection((door.linkedDoor.WalkDirection.position - playerController.transform.position).normalized);
|
||||
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
// move character a little more
|
||||
while (fadeTime < moveDuration)
|
||||
{
|
||||
playerController.WalkInDirection((door.linkedDoor.WalkDirection.position - playerController.transform.position).normalized);
|
||||
fadeTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user