|
|
@ -21,13 +21,16 @@ public class PlayerController : MonoBehaviour |
|
|
|
private Vector3 moveDirection = Vector3.zero; |
|
|
|
private float moveDelta; |
|
|
|
private float lastMoveTime; |
|
|
|
private bool isRagdoll = false; |
|
|
|
|
|
|
|
public bool isGrounded { get { return (cController != null) ? cController.isGrounded : false; } } |
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start() |
|
|
|
{ |
|
|
|
speedMulitplier = UnityEngine.Random.Range(0.8f, 1.2f); |
|
|
|
cController = GetComponent<CharacterController>(); |
|
|
|
randomizer = UnityEngine.Random.Range(0,10); |
|
|
|
randomizer = UnityEngine.Random.Range(0, 10); |
|
|
|
cam = FindObjectOfType<Camera>(); |
|
|
|
herd = FindObjectOfType<HerdController>(); |
|
|
|
} |
|
|
@ -36,7 +39,7 @@ public class PlayerController : MonoBehaviour |
|
|
|
{ |
|
|
|
receivedInput = input; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void UpdatePosition() |
|
|
|
{ |
|
|
|
moveDelta = Time.time - lastMoveTime; |
|
|
@ -59,15 +62,21 @@ public class PlayerController : MonoBehaviour |
|
|
|
|
|
|
|
if (cController.isGrounded) |
|
|
|
{ |
|
|
|
moveDirection = new Vector3(HorseX, 0, HorseZ); |
|
|
|
moveDirection *= walkSpeed * speedMulitplier; |
|
|
|
if (!isRagdoll) |
|
|
|
{ |
|
|
|
moveDirection = Vector3.zero; |
|
|
|
moveDirection += new Vector3(HorseX, 0, HorseZ) * (walkSpeed * (1 + speedMulitplier)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
moveDirection.y -= gravity * Time.deltaTime; |
|
|
|
|
|
|
|
cController.Move(moveDirection * Time.deltaTime); |
|
|
|
if (cController.isGrounded) |
|
|
|
isRagdoll = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//float rotateTo = RotateObject(HorseX, HorseZ);
|
|
|
@ -117,11 +126,12 @@ public class PlayerController : MonoBehaviour |
|
|
|
|
|
|
|
public IEnumerator RandomWait(float wait) |
|
|
|
{ |
|
|
|
yield return new WaitForSeconds(UnityEngine.Random.Range(0, wait/2)); |
|
|
|
Vector3 input = receivedInput; |
|
|
|
yield return new WaitForSeconds(UnityEngine.Random.Range(0, wait / 2)); |
|
|
|
|
|
|
|
if (cController.isGrounded) |
|
|
|
if (/*cController.isGrounded*/ true) |
|
|
|
{ |
|
|
|
Vector3 rotateDir = new Vector3(90 * Math.Sign(receivedInput.y), 0, -90 * Math.Sign(receivedInput.x)); |
|
|
|
Vector3 rotateDir = new Vector3(90 * Math.Sign(input.y), 0, -90 * Math.Sign(input.x)); |
|
|
|
model.transform.Rotate(rotateDir, Space.World); |
|
|
|
} |
|
|
|
} |
|
|
@ -136,9 +146,16 @@ public class PlayerController : MonoBehaviour |
|
|
|
// Update is called once per frame
|
|
|
|
void Update() |
|
|
|
{ |
|
|
|
speedMulitplier = (Mathf.Sin(Time.time * UnityEngine.Random.Range(0.9f,1.1f) + randomizer) + 2); |
|
|
|
directionRandmoizer = Mathf.Cos(Time.time + randomizer / 2) * 0.3f; |
|
|
|
speedMulitplier = ((Mathf.Sin(Time.time * UnityEngine.Random.Range(0.95f, 1.05f) + randomizer) + 2) * 0.25f); |
|
|
|
directionRandmoizer = Mathf.Cos(Time.time + randomizer / 2) * 0.0f; |
|
|
|
UpdatePosition(); |
|
|
|
DestroyOffCamera(); |
|
|
|
} |
|
|
|
|
|
|
|
public void AddForce(Vector3 direction) |
|
|
|
{ |
|
|
|
moveDirection += direction; |
|
|
|
isRagdoll = true; |
|
|
|
} |
|
|
|
|
|
|
|
} |