Browse Source

Updates to camera and horse destroy function

master
NickFowler 4 years ago
parent
commit
3162a8f375
5 changed files with 320 additions and 18 deletions
  1. +283
    -3
      Assets/Scenes/SampleScene.unity
  2. +8
    -3
      Assets/Scripts/Input/DynamicCamera.cs
  3. +6
    -0
      Assets/Scripts/Input/HerdController.cs
  4. +22
    -12
      Assets/Scripts/Input/PlayerController.cs
  5. +1
    -0
      Assets/WorldAssets/Prefabs/Horse.prefab

+ 283
- 3
Assets/Scenes/SampleScene.unity View File

@ -121,6 +121,99 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1 &33826417
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 33826421}
- component: {fileID: 33826420}
- component: {fileID: 33826419}
- component: {fileID: 33826418}
m_Layer: 0
m_Name: Cube (3)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &33826418
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 33826417}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &33826419
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 33826417}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 950d424518c282344956b5e374c7b715, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &33826420
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 33826417}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &33826421
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 33826417}
m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: -21.69, y: -1.012, z: 20.28}
m_LocalScale: {x: 15.892654, y: 14.241516, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0}
--- !u!1 &380641380 --- !u!1 &380641380
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -214,6 +307,99 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &383575962
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 383575966}
- component: {fileID: 383575965}
- component: {fileID: 383575964}
- component: {fileID: 383575963}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!135 &383575963
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383575962}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &383575964
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383575962}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &383575965
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383575962}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &383575966
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 383575962}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -5.23, z: 7.37}
m_LocalScale: {x: 5, y: 5, z: 5}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &705507993 --- !u!1 &705507993
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -393,12 +579,105 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 778362041} m_GameObject: {fileID: 778362041}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.8334109, y: 0.2, z: 27.1}
m_LocalScale: {x: 44.013, y: 16.279, z: 1}
m_LocalPosition: {x: 0.8334109, y: -1.012, z: 27.1}
m_LocalScale: {x: 44.013, y: 14.241516, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &903473255
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 903473259}
- component: {fileID: 903473258}
- component: {fileID: 903473257}
- component: {fileID: 903473256}
m_Layer: 0
m_Name: Cube (2)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &903473256
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 903473255}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &903473257
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 903473255}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &903473258
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 903473255}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &903473259
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 903473255}
m_LocalRotation: {x: -0.23348022, y: -0, z: -0, w: 0.97236156}
m_LocalPosition: {x: 9.03, y: -5.55, z: 0}
m_LocalScale: {x: 7.4761, y: 1, z: 4.4214}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: -27.004002, y: 0, z: 0}
--- !u!1 &963194225 --- !u!1 &963194225
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -544,9 +823,10 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Prefab: {fileID: 7371939184051845554, guid: f5c2c9744b6f46e4e95ca41ab1d8d560, type: 3} Prefab: {fileID: 7371939184051845554, guid: f5c2c9744b6f46e4e95ca41ab1d8d560, type: 3}
HerdCount: 20
HerdCount: 100
SpawnPoint: {fileID: 0} SpawnPoint: {fileID: 0}
WaitTime: 0.2 WaitTime: 0.2
Centre: {fileID: 0}
--- !u!4 &1457452761 --- !u!4 &1457452761
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

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

@ -2,16 +2,21 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
public class DynamicCamera : MonoBehaviour
{ {
public GameObject target; public GameObject target;
public float camHeight; public float camHeight;
void Start()
{
}
void Follow() void Follow()
{ {
Vector3 tempDest = target.transform.position; Vector3 tempDest = target.transform.position;
tempDest.y = camHeight;
Vector3 destination = Vector3.Lerp(transform.position, tempDest, 1);
tempDest -= transform.forward * camHeight;
Vector3 destination = Vector3.Lerp(transform.position, tempDest, 10f * Time.deltaTime);
transform.position = destination; transform.position = destination;
} }

+ 6
- 0
Assets/Scripts/Input/HerdController.cs View File

@ -110,6 +110,12 @@ public class HerdController : MonoBehaviour
Centre.position = Herd.Aggregate(new Vector3(0, 0, 0), (s, v) => s + v.transform.position) / (float)Herd.Count; Centre.position = Herd.Aggregate(new Vector3(0, 0, 0), (s, v) => s + v.transform.position) / (float)Herd.Count;
} }
public void RemoveHorse(PlayerController horse)
{
Herd.Remove(horse);
Destroy(horse.gameObject);
}
private bool SpawnPositionValid(Vector3 position, Quaternion rotation, Bounds bound) private bool SpawnPositionValid(Vector3 position, Quaternion rotation, Bounds bound)
{ {

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

@ -10,6 +10,8 @@ public class PlayerController : MonoBehaviour
public float gravity; public float gravity;
public GameObject model; public GameObject model;
public CharacterController cController; public CharacterController cController;
public Camera cam;
public HerdController herd;
public float speedMulitplier; public float speedMulitplier;
private float randomizer; private float randomizer;
@ -26,6 +28,8 @@ public class PlayerController : MonoBehaviour
speedMulitplier = UnityEngine.Random.Range(0.8f, 1.2f); speedMulitplier = UnityEngine.Random.Range(0.8f, 1.2f);
cController = GetComponent<CharacterController>(); cController = GetComponent<CharacterController>();
randomizer = UnityEngine.Random.Range(0,10); randomizer = UnityEngine.Random.Range(0,10);
cam = FindObjectOfType<Camera>();
herd = FindObjectOfType<HerdController>();
} }
public void SetMovement(Vector2 input) public void SetMovement(Vector2 input)
@ -38,22 +42,21 @@ public class PlayerController : MonoBehaviour
moveDelta = Time.time - lastMoveTime; moveDelta = Time.time - lastMoveTime;
lastMoveTime = Time.time; lastMoveTime = Time.time;
if (receivedInput.magnitude == 0)
return;
float HorseX, HorseZ; float HorseX, HorseZ;
HorseZ = receivedInput.y; HorseZ = receivedInput.y;
HorseX = receivedInput.x; HorseX = receivedInput.x;
if (Mathf.Abs(HorseZ) == Mathf.Min(Mathf.Abs(HorseZ), Mathf.Abs(HorseX)))
if (receivedInput.magnitude != 0)
{ {
HorseZ += directionRandmoizer;
if (Mathf.Abs(HorseZ) == Mathf.Min(Mathf.Abs(HorseZ), Mathf.Abs(HorseX)))
{
HorseZ += directionRandmoizer;
}
else
{
HorseX += directionRandmoizer;
}
} }
else
{
HorseX += directionRandmoizer;
}
if (cController.isGrounded) if (cController.isGrounded)
{ {
moveDirection = new Vector3(HorseX, 0, HorseZ); moveDirection = new Vector3(HorseX, 0, HorseZ);
@ -123,12 +126,19 @@ public class PlayerController : MonoBehaviour
} }
} }
public void DestroyOffCamera()
{
Vector3 viewPos = cam.WorldToViewportPoint(transform.position);
if (viewPos.y < -0.1)
herd.RemoveHorse(this);
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
speedMulitplier = (Mathf.Sin(Time.time * UnityEngine.Random.Range(0.9f,1.1f) + randomizer) + 2); speedMulitplier = (Mathf.Sin(Time.time * UnityEngine.Random.Range(0.9f,1.1f) + randomizer) + 2);
directionRandmoizer = Mathf.Cos(Time.time + randomizer / 2) * 0.3f; directionRandmoizer = Mathf.Cos(Time.time + randomizer / 2) * 0.3f;
UpdatePosition(); UpdatePosition();
DestroyOffCamera();
} }
} }

+ 1
- 0
Assets/WorldAssets/Prefabs/Horse.prefab View File

@ -81,6 +81,7 @@ MonoBehaviour:
gravity: 35 gravity: 35
model: {fileID: 760734042007802935} model: {fileID: 760734042007802935}
cController: {fileID: 0} cController: {fileID: 0}
speedMulitplier: 0
--- !u!143 &7371939184051845555 --- !u!143 &7371939184051845555
CharacterController: CharacterController:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

Loading…
Cancel
Save