Browse Source

Added camera + force + stuff

master
Joshua Reason 4 years ago
parent
commit
da7ffa3a31
4 changed files with 70 additions and 19 deletions
  1. +33
    -5
      Assets/Scripts/ExplosionTest.cs
  2. +3
    -0
      Assets/Scripts/Input/DynamicCamera.cs
  3. +12
    -2
      Assets/Scripts/Input/HerdController.cs
  4. +22
    -12
      Assets/Scripts/Input/PlayerController.cs

+ 33
- 5
Assets/Scripts/ExplosionTest.cs View File

@ -7,16 +7,44 @@ public class ExplosionTest : MonoBehaviour
[SerializeField]
private float Force = 1;
private void OnTriggerEnter(Collider other)
[SerializeField]
private float speed;
[SerializeField]
private Vector3 direction;
Vector3 start;
float ratio;
private void Start()
{
start = transform.position;
}
private void Update()
{
ratio = Mathf.Sin(Time.time * speed);
transform.position = Vector3.Lerp(start, start + direction, (ratio+1)/2);
}
private void OnDrawGizmosSelected()
{
if (Application.isPlaying)
Gizmos.DrawWireSphere(start + direction, 10);
else
Gizmos.DrawWireSphere(transform.position + direction, 10);
}
private void OnTriggerStay(Collider other)
{
var horse = other.GetComponent<PlayerController>();
if (horse != null)
{
Vector3 force = Vector3.up * 2 + Vector3.ProjectOnPlane(Random.insideUnitSphere, Vector3.up) * Force;
horse.AddForce(force);
Debug.DrawRay(horse.transform.position, force, Color.red, 1f);
Debug.Log("Throwing horse");
horse.AddForce((direction.normalized * Mathf.Cos(Time.time *speed) + Vector3.up) * Force);
Debug.DrawRay(horse.transform.position, (direction.normalized + Vector3.up) * Mathf.Cos(Time.time * speed) * Force, Color.red, 0.5f);
}
}
}

+ 3
- 0
Assets/Scripts/Input/DynamicCamera.cs View File

@ -15,6 +15,9 @@ public class DynamicCamera : MonoBehaviour
void Follow()
{
Vector3 tempDest = target.transform.position;
camHeight = target.transform.localScale.magnitude;
tempDest -= transform.forward * camHeight;
Vector3 destination = Vector3.Lerp(transform.position, tempDest, 10f * Time.deltaTime);
transform.position = destination;

+ 12
- 2
Assets/Scripts/Input/HerdController.cs View File

@ -106,8 +106,18 @@ public class HerdController : MonoBehaviour
}
if (Centre != null)
Centre.position = Herd.Aggregate(new Vector3(0, 0, 0), (s, v) => s + v.transform.position) / (float)Herd.Count;
if (Herd?.Count > 0)
{
Bounds bound = new Bounds(Herd[0].transform.position, Vector3.zero);
foreach (PlayerController horse in Herd)
{
if (horse.isGrounded || Time.time < 5)
bound.Encapsulate(horse.transform.position);
}
Centre.position = bound.center;
Centre.localScale = bound.size * 0.8f;
}
}
public void RemoveHorse(PlayerController horse)

+ 22
- 12
Assets/Scripts/Input/PlayerController.cs View File

@ -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,8 +146,8 @@ 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();
}
@ -145,7 +155,7 @@ public class PlayerController : MonoBehaviour
public void AddForce(Vector3 direction)
{
moveDirection += direction;
transform.Translate(direction*Time.deltaTime);
isRagdoll = true;
}
}

Loading…
Cancel
Save