From 6f863020a220f1f425c1442cdc78d52edb456d54 Mon Sep 17 00:00:00 2001 From: NickFowler Date: Sat, 1 Feb 2020 15:40:19 +1100 Subject: [PATCH] Updates to player movement --- Assets/Scripts/Input/DynamicCamera.cs | 20 ++++++++++++ Assets/Scripts/Input/DynamicCamera.cs.meta | 11 +++++++ Assets/Scripts/Input/HerdController.cs | 2 +- Assets/Scripts/Input/PlayerController.cs | 26 +++++++++------ Assets/WorldAssets/Prefabs/Horse.prefab | 37 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 Assets/Scripts/Input/DynamicCamera.cs create mode 100644 Assets/Scripts/Input/DynamicCamera.cs.meta diff --git a/Assets/Scripts/Input/DynamicCamera.cs b/Assets/Scripts/Input/DynamicCamera.cs new file mode 100644 index 0000000..6a58fae --- /dev/null +++ b/Assets/Scripts/Input/DynamicCamera.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class NewBehaviourScript : MonoBehaviour +{ + public GameObject Target; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Input/DynamicCamera.cs.meta b/Assets/Scripts/Input/DynamicCamera.cs.meta new file mode 100644 index 0000000..c00f0a6 --- /dev/null +++ b/Assets/Scripts/Input/DynamicCamera.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49812763c430a0f4cb0f5e99a203f1ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Input/HerdController.cs b/Assets/Scripts/Input/HerdController.cs index 5753057..ff1f803 100644 --- a/Assets/Scripts/Input/HerdController.cs +++ b/Assets/Scripts/Input/HerdController.cs @@ -92,7 +92,7 @@ public class HerdController : MonoBehaviour { foreach (PlayerController pc in Herd) { - pc.MoveObject(); + pc.MoveObject(WaitTime); } yield return new WaitForSeconds(WaitTime); diff --git a/Assets/Scripts/Input/PlayerController.cs b/Assets/Scripts/Input/PlayerController.cs index 5113a5c..d4603e4 100644 --- a/Assets/Scripts/Input/PlayerController.cs +++ b/Assets/Scripts/Input/PlayerController.cs @@ -2,16 +2,20 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using Random = System.Random; public class PlayerController : MonoBehaviour { public float walkSpeed; public GameObject model; + private float speedMulitplier; + private Vector2 receivedInput; // Start is called before the first frame update void Start() { + speedMulitplier = UnityEngine.Random.Range(0.8f, 1.2f); } public void SetMovement(Vector2 input) @@ -27,8 +31,8 @@ public class PlayerController : MonoBehaviour float rotateTo = RotateObject(HorseX, HorseZ); - HorseZ *= walkSpeed; - HorseX *= walkSpeed; + HorseZ *= Time.deltaTime * walkSpeed * speedMulitplier; + HorseX *= Time.deltaTime * walkSpeed * speedMulitplier; transform.Translate(HorseX, 0, HorseZ); @@ -66,18 +70,22 @@ public class PlayerController : MonoBehaviour return to; } - public void MoveObject() + public void MoveObject(float wait) { - UpdatePosition(); - if (receivedInput.x != 0 || receivedInput.y != 0) - { - model.transform.Rotate(-90, 0, 0); - } + StartCoroutine(RandomWait(wait)); + } + + public IEnumerator RandomWait(float wait) + { + yield return new WaitForSeconds(UnityEngine.Random.Range(0, wait/2)); + + Vector3 rotateDir = new Vector3(90 * Math.Sign(receivedInput.y), 0, -90 * Math.Sign(receivedInput.x)); + model.transform.Rotate(rotateDir, Space.World); } // Update is called once per frame void Update() { - + UpdatePosition(); } } diff --git a/Assets/WorldAssets/Prefabs/Horse.prefab b/Assets/WorldAssets/Prefabs/Horse.prefab index db77a91..531d448 100644 --- a/Assets/WorldAssets/Prefabs/Horse.prefab +++ b/Assets/WorldAssets/Prefabs/Horse.prefab @@ -64,7 +64,7 @@ CharacterController: m_StepOffset: 0.3 m_SkinWidth: 0.08 m_MinMoveDistance: 0.001 - m_Center: {x: 0, y: 1, z: 0} + m_Center: {x: 0, y: 0, z: 0} --- !u!1001 &7371939184763441364 PrefabInstance: m_ObjectHideFlags: 0 @@ -77,6 +77,11 @@ PrefabInstance: propertyPath: m_Name value: Cube objectReference: {fileID: 0} + - target: {fileID: 687741958870159176, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: -0.5 + objectReference: {fileID: 0} - target: {fileID: 1281286576698487906, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3} propertyPath: m_LocalPosition.x @@ -132,6 +137,36 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 1317434602306065355, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: -0.5 + objectReference: {fileID: 0} + - target: {fileID: 1652654074722291708, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: -0.5 + objectReference: {fileID: 0} + - target: {fileID: 1731993206513226773, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.06 + objectReference: {fileID: 0} + - target: {fileID: 2458785659072919632, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: -0.5 + objectReference: {fileID: 0} + - target: {fileID: 7081464788313828805, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.15 + objectReference: {fileID: 0} + - target: {fileID: 8693433057835279953, guid: 4d11c77c6b58b7040a8596bc47f45d97, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.577 + objectReference: {fileID: 0} m_RemovedComponents: - {fileID: -641725564868193174, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3} - {fileID: 6187295151528677371, guid: 4d11c77c6b58b7040a8596bc47f45d97, type: 3}