From 8b37d990eee7ac4e0729450624c834bd223c3047 Mon Sep 17 00:00:00 2001 From: ALoTron <34157676+ALoTron@users.noreply.github.com> Date: Sat, 21 Apr 2018 16:55:39 +0200 Subject: [PATCH 1/4] Added Mob-Entity --- Assets/Scripts/Entities/Mob.cs | 16 ++++++++++++++++ Assets/Scripts/Entities/Mob.cs.meta | 11 +++++++++++ Assets/Scripts/Objectives/EntityObjective.cs | 1 - 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Assets/Scripts/Entities/Mob.cs create mode 100644 Assets/Scripts/Entities/Mob.cs.meta diff --git a/Assets/Scripts/Entities/Mob.cs b/Assets/Scripts/Entities/Mob.cs new file mode 100644 index 0000000..0534e14 --- /dev/null +++ b/Assets/Scripts/Entities/Mob.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Mob : MonoBehaviour { + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/Assets/Scripts/Entities/Mob.cs.meta b/Assets/Scripts/Entities/Mob.cs.meta new file mode 100644 index 0000000..2673846 --- /dev/null +++ b/Assets/Scripts/Entities/Mob.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7c34c451bf3a8c24f823ca94395753ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Objectives/EntityObjective.cs b/Assets/Scripts/Objectives/EntityObjective.cs index cb26624..f454c08 100644 --- a/Assets/Scripts/Objectives/EntityObjective.cs +++ b/Assets/Scripts/Objectives/EntityObjective.cs @@ -10,7 +10,6 @@ public class EntityObjective : Objective{ public EntityObjective(Room objectiveCaller, List entityList) : base(objectiveCaller) { this.entityList = entityList; - this.spawnPointList = spawnPointList; spawnPointList = objectiveCaller.GetSpawnpoints (); } From 4b1e2b1dc47e9d4342b3dbfe7bfa179e0c3f80fe Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 21 Apr 2018 17:18:17 +0200 Subject: [PATCH 2/4] add door prefab --- Assets/Prefabs/Door.prefab | 105 ++++++++++++++++++++++++++++++++ Assets/Prefabs/Door.prefab.meta | 8 +++ 2 files changed, 113 insertions(+) create mode 100644 Assets/Prefabs/Door.prefab create mode 100644 Assets/Prefabs/Door.prefab.meta diff --git a/Assets/Prefabs/Door.prefab b/Assets/Prefabs/Door.prefab new file mode 100644 index 0000000..163069e --- /dev/null +++ b/Assets/Prefabs/Door.prefab @@ -0,0 +1,105 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1046373619020340} + m_IsPrefabParent: 1 +--- !u!1 &1046373619020340 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4708397045567336} + - component: {fileID: 114712631247209960} + - component: {fileID: 61859685447846418} + - component: {fileID: 61191558022818200} + m_Layer: 0 + m_Name: UpperDoor + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4708397045567336 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1046373619020340} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 9.06, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &61191558022818200 +BoxCollider2D: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1046373619020340} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: -0.3731112, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 3.025469, y: 1} + m_EdgeRadius: 0 +--- !u!61 &61859685447846418 +BoxCollider2D: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1046373619020340} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: -0.37311125, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 3.0254688, y: 1} + m_EdgeRadius: 0 +--- !u!114 &114712631247209960 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1046373619020340} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b8cc30ac6e59724bba6536a17fbf027, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/Door.prefab.meta b/Assets/Prefabs/Door.prefab.meta new file mode 100644 index 0000000..01c667b --- /dev/null +++ b/Assets/Prefabs/Door.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 88e4526bbc633401ebdaaffa8a16c3aa +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: From 09116b9b543f57e9fce0b06edeb634f7c968dbd5 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sat, 21 Apr 2018 17:22:29 +0200 Subject: [PATCH 3/4] DRIFTING! --- Assets/Scenes/JanDevScene.unity | 25 +++++++++++++++ Assets/Scripts/PlayerMovement.cs | 54 ++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/Assets/Scenes/JanDevScene.unity b/Assets/Scenes/JanDevScene.unity index 45ef169..e99567f 100644 --- a/Assets/Scenes/JanDevScene.unity +++ b/Assets/Scenes/JanDevScene.unity @@ -169,6 +169,31 @@ Prefab: propertyPath: m_LocalPosition.x value: 0 objectReference: {fileID: 0} + - target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f, + type: 2} + propertyPath: curveSpeed + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f, + type: 2} + propertyPath: turnSpeed + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f, + type: 2} + propertyPath: drift + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f, + type: 2} + propertyPath: friction + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 114874769993434856, guid: 3d1911457c1e44f53b6b4044334db52f, + type: 2} + propertyPath: acceleration + value: 5 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 3d1911457c1e44f53b6b4044334db52f, type: 2} m_IsPrefabParent: 0 diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index c2fceed..43ee511 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -2,42 +2,50 @@ public class PlayerMovement : MonoBehaviour { - public float power = 3; - public float turnpower = 2; - public float curveSpeed = 0.5f; - Vector3 curspeed; + [SerializeField] + public float acceleration = 3; + [SerializeField] + public float friction = 0.1f; + [SerializeField] + public float turnSpeed = 2; + [SerializeField] + public float drift = 1f; + Rigidbody2D rigidbody2D; // Use this for initialization - void Start() - { + void Start() { rigidbody2D = GetComponent(); } - void FixedUpdate() { - - curspeed = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0); - - //curspeed = curspeed.normalized; - //curspeed *= maxspeed; - - rigidbody2D.AddForce(transform.up * power); - Vector3 forwardNorm = (transform.localRotation * Vector3.up).normalized * curspeed.magnitude; - Vector3 br = forwardNorm - curspeed; - br *= curveSpeed; - rigidbody2D.AddForce(br); - //Debug.Log(br); + Vector3 speedVec = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0); + float speed = speedVec.magnitude; + { // Forward + rigidbody2D.AddForce(transform.up * acceleration); + } + {// Drag + Vector3 drag = speedVec.normalized * speed * speed * friction * -1; + rigidbody2D.AddForce(drag); + Debug.DrawLine(transform.position, transform.position + drag, Color.cyan, 0.01f, false); + } + { // Drift + Vector3 forwardNorm = (transform.localRotation * Vector3.up).normalized * speedVec.magnitude; + Vector3 br = forwardNorm - speedVec; + br *= drift; + rigidbody2D.AddForce(br); + //Debug.Log(br); + Debug.DrawLine(transform.position, transform.position + br, Color.red, 0.01f, false); + } if (Input.GetKey(KeyCode.A)){ - transform.Rotate(Vector3.forward * turnpower); + transform.Rotate(Vector3.forward * turnSpeed); } if (Input.GetKey(KeyCode.D)) { - transform.Rotate(Vector3.forward * -turnpower); + transform.Rotate(Vector3.forward * -turnSpeed); } // Debug lines - Debug.DrawLine(transform.position, transform.position + curspeed, Color.magenta, 0.01f, false); - Debug.DrawLine(transform.position, transform.position + br, Color.red, 0.01f, false); + Debug.DrawLine(transform.position, transform.position + speedVec, Color.magenta, 0.01f, false); Debug.DrawLine(transform.position, transform.position + transform.localRotation * Vector3.up, Color.yellow, 0.01f, false); //Debug.Log(transform.localRotation.eulerAngles); From bd9f61a671e9a7717cc2d9ce52e8c809cc3dbde7 Mon Sep 17 00:00:00 2001 From: ALoTron <34157676+ALoTron@users.noreply.github.com> Date: Sat, 21 Apr 2018 17:27:28 +0200 Subject: [PATCH 4/4] Done some Stuff, and some more ... --- Assets/Scripts/Entities/Collectable.cs | 2 +- Assets/Scripts/Entities/Entity.cs | 20 +++-------- Assets/Scripts/Entities/Mob.cs | 36 +++++++++++++++----- Assets/Scripts/Objectives/EntityObjective.cs | 16 +++++---- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/Entities/Collectable.cs b/Assets/Scripts/Entities/Collectable.cs index 4194668..707ab5d 100644 --- a/Assets/Scripts/Entities/Collectable.cs +++ b/Assets/Scripts/Entities/Collectable.cs @@ -4,5 +4,5 @@ using UnityEngine; public class Collectable : Entity{ - public Collectable (EntityObjective referringObjective, GameObject entityPrefab) : base(referringObjective, entityPrefab) {} + public Collectable (EntityObjective referringObjective) : base(referringObjective) {} } diff --git a/Assets/Scripts/Entities/Entity.cs b/Assets/Scripts/Entities/Entity.cs index f640f49..9c91404 100644 --- a/Assets/Scripts/Entities/Entity.cs +++ b/Assets/Scripts/Entities/Entity.cs @@ -2,31 +2,19 @@ using System.Collections.Generic; using UnityEngine; -public abstract class Entity { +public abstract class Entity : MonoBehaviour{ EntityObjective referringObjective; - GameObject entityPrefab; - GameObject instance; // Constructor - public Entity(EntityObjective referringObjective, GameObject entityPrefab) + public Entity(EntityObjective referringObjective) { this.referringObjective = referringObjective; - this.entityPrefab = entityPrefab; - } - - // spawns the entity - public void Spawn(Transform spawnPoint) - { - // instance = GameObject.Instantiate (entityPrefab); - // instance.transform = spawnPoint; } // kills the entity public void Kill() { - GameObject.Destroy (instance); - referringObjective.Remove (this); - - instance = null; + if(referringObjective != null) + referringObjective.Remove (this.gameObject); } } diff --git a/Assets/Scripts/Entities/Mob.cs b/Assets/Scripts/Entities/Mob.cs index 0534e14..a8ef325 100644 --- a/Assets/Scripts/Entities/Mob.cs +++ b/Assets/Scripts/Entities/Mob.cs @@ -2,15 +2,35 @@ using System.Collections.Generic; using UnityEngine; -public class Mob : MonoBehaviour { +public abstract class Mob : Entity { + readonly int maxHP; + int currentHP; + bool isDead; - // Use this for initialization - void Start () { - + // Constructor + public Mob(EntityObjective referringObjective, int maxHP) : base(referringObjective) + { + this.maxHP = maxHP; + currentHP = maxHP; + + isDead = false; } - - // Update is called once per frame - void Update () { - + + // inflicts damage to this mob + public void InflictDamage(int damage) + { + currentHP -= damage; + if (!isDead && currentHP <= 0) + { + base.Kill (); + isDead = true; + } + } + + // Heals the mob + public void Heal(int healAmount) + { + if (!isDead) + currentHP = (currentHP + healAmount > currentHP) ? maxHP : currentHP + healAmount; } } diff --git a/Assets/Scripts/Objectives/EntityObjective.cs b/Assets/Scripts/Objectives/EntityObjective.cs index f454c08..9871471 100644 --- a/Assets/Scripts/Objectives/EntityObjective.cs +++ b/Assets/Scripts/Objectives/EntityObjective.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using UnityEngine; public class EntityObjective : Objective{ - List entityList; + List prefabList; + List entityList; List spawnPointList; // Constructor - public EntityObjective(Room objectiveCaller, List entityList) : base(objectiveCaller) + public EntityObjective(Room objectiveCaller, List prefabList) : base(objectiveCaller) { - this.entityList = entityList; + this.prefabList = prefabList; spawnPointList = objectiveCaller.GetSpawnpoints (); } @@ -18,14 +19,17 @@ public class EntityObjective : Objective{ { Random newRand = new Random (); - foreach (Entity i in entityList) - i.Spawn(spawnPointList[Random.Range(0, spawnPointList.Count)]); + foreach (GameObject i in prefabList) + { + GameObject tempObject = GameObject.Instantiate (i); + tempObject.transform.position = spawnPointList [Random.Range (0, spawnPointList.Count)].position; + } objectiveCaller.Lock(); } // Removes the entity from the list and completes the objective, if the list is empty - public void Remove(Entity inputEntity) + public void Remove(GameObject inputEntity) { entityList.Remove (inputEntity); if (entityList.Count == 0)