fix gravity with door transition
This commit is contained in:
@@ -953,13 +953,13 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 151657444}
|
m_GameObject: {fileID: 151657444}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
|
||||||
m_LocalPosition: {x: -0.475, y: 34.3, z: -0}
|
m_LocalPosition: {x: -0.47499996, y: 34.3, z: 0.00000012626319}
|
||||||
m_LocalScale: {x: 1.1708915, y: 69.57974, z: 1.1708915}
|
m_LocalScale: {x: 1.1708915, y: 69.57974, z: 1.1708915}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 441147620}
|
m_Father: {fileID: 441147620}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
|
||||||
--- !u!114 &151657446
|
--- !u!114 &151657446
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ void Start()
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
moveDir = Vector3.zero;
|
||||||
|
|
||||||
if (hasControl)
|
if (hasControl)
|
||||||
{
|
{
|
||||||
if (!isDigging)
|
if (!isDigging)
|
||||||
@@ -37,8 +39,8 @@ void Update()
|
|||||||
TryInteract();
|
TryInteract();
|
||||||
}
|
}
|
||||||
|
|
||||||
Walk();
|
|
||||||
DigDetector();
|
DigDetector();
|
||||||
|
ApplyWalk();
|
||||||
|
|
||||||
// TODO: This is just for testing, remove or clean up if used
|
// TODO: This is just for testing, remove or clean up if used
|
||||||
if (Input.GetKeyDown(KeyCode.LeftShift))
|
if (Input.GetKeyDown(KeyCode.LeftShift))
|
||||||
@@ -46,12 +48,15 @@ void Update()
|
|||||||
cameraController.RotateCam();
|
cameraController.RotateCam();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplyGravity();
|
||||||
|
DoMovement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handle movement
|
/// Apply walking inputs to moveDir
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Walk()
|
void ApplyWalk()
|
||||||
{
|
{
|
||||||
float verticalMovement = 0;
|
float verticalMovement = 0;
|
||||||
float horizontalMovement = 0;
|
float horizontalMovement = 0;
|
||||||
@@ -72,17 +77,38 @@ void Walk()
|
|||||||
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
||||||
moveDir = matrix.MultiplyPoint3x4(moveDir);
|
moveDir = matrix.MultiplyPoint3x4(moveDir);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply gravity to moveDir
|
||||||
|
/// </summary>
|
||||||
|
void ApplyGravity()
|
||||||
|
{
|
||||||
moveDir *= walkSpeed;
|
moveDir *= walkSpeed;
|
||||||
|
|
||||||
if (!characterController.isGrounded)
|
if (!characterController.isGrounded)
|
||||||
{
|
{
|
||||||
moveDir.y = -gravity;
|
moveDir.y = -gravity;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Move character with moveDir
|
||||||
|
/// </summary>
|
||||||
|
void DoMovement()
|
||||||
|
{
|
||||||
characterController.Move(moveDir * Time.deltaTime);
|
characterController.Move(moveDir * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pass movement into character controller, lets us expose function without exposing
|
||||||
|
/// whole char controller
|
||||||
|
/// </summary>
|
||||||
|
public void CharacterControllerMove(Vector3 movement)
|
||||||
|
{
|
||||||
|
characterController.Move(movement);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Detect input for digging (will eventually be tool agnostic)
|
/// Detect input for digging (will eventually be tool agnostic)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -33,7 +33,11 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
|
|||||||
Color blackScreenColor = Color.black;
|
Color blackScreenColor = Color.black;
|
||||||
|
|
||||||
playerController.SetCharacterControl(false);
|
playerController.SetCharacterControl(false);
|
||||||
// Play enter room animation (wait seconds during animation)
|
// 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)
|
if (door.requiresInteraction)
|
||||||
yield return new WaitForSeconds(0.2f);
|
yield return new WaitForSeconds(0.2f);
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ IEnumerator EnterRoomCoroutine(RoomDoor door)
|
|||||||
}
|
}
|
||||||
fadeTime = 0;
|
fadeTime = 0;
|
||||||
|
|
||||||
transform.position = door.linkedDoor.transform.position;
|
playerController.CharacterControllerMove(door.linkedDoor.transform.position - transform.position);
|
||||||
playerController.DougBody.transform.rotation = door.linkedDoor.transform.rotation;
|
playerController.DougBody.transform.rotation = door.linkedDoor.transform.rotation;
|
||||||
|
|
||||||
while (fadeTime < fadeDuration)
|
while (fadeTime < fadeDuration)
|
||||||
|
|||||||
Reference in New Issue
Block a user