Add artist shooting, and refactor generation movment

This commit is contained in:
Isaac Shoebottom 2023-02-16 23:44:32 -04:00
parent 2dad7631dd
commit 08ea2e0dcf
12 changed files with 273 additions and 24 deletions

View File

@ -26,7 +26,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2276488776047960095} m_GameObject: {fileID: 2276488776047960095}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.4975915, y: -0.11709992, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -97,3 +97,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 06caeb0582820f948af0d6f38028c18c, type: 3} m_Script: {fileID: 11500000, guid: 06caeb0582820f948af0d6f38028c18c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
range: 50
projectile: {fileID: 3544353787361441734, guid: aa1ba1d671c82454aa7a59fc067bba98, type: 3}

View File

@ -0,0 +1,148 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3544353787361441734
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 724014420718400120}
- component: {fileID: 2790118073472331148}
- component: {fileID: -4088027269952991048}
- component: {fileID: -3318894246017771297}
- component: {fileID: 1388709940240671698}
m_Layer: 0
m_Name: ArtistPencilAttack
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &724014420718400120
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3544353787361441734}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.4, y: 0.1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &2790118073472331148
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3544353787361441734}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, 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: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 1035096185
m_SortingLayer: -1
m_SortingOrder: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 1, g: 0.92054325, b: 0, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!50 &-4088027269952991048
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3544353787361441734}
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 0
m_CollisionDetection: 0
m_Constraints: 0
--- !u!61 &-3318894246017771297
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3544353787361441734}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &1388709940240671698
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3544353787361441734}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7cdb7de3f3533494eae1b220ca0aebe1, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: aa1ba1d671c82454aa7a59fc067bba98
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -28,7 +28,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1458536803320539101} m_GameObject: {fileID: 1458536803320539101}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.4975915, y: -0.11709992, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -99,6 +99,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6d151e6102b72db4590ce83309573f1c, type: 3} m_Script: {fileID: 11500000, guid: 6d151e6102b72db4590ce83309573f1c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
speed: 1
--- !u!50 &7146678828090736945 --- !u!50 &7146678828090736945
Rigidbody2D: Rigidbody2D:
serializedVersion: 4 serializedVersion: 4

View File

@ -28,7 +28,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2624247600710686983} m_GameObject: {fileID: 2624247600710686983}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.7311517, y: 0.074633844, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.1, y: 0.1, z: 1} m_LocalScale: {x: 0.1, y: 0.1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []

View File

@ -303,7 +303,7 @@ SpriteRenderer:
m_AutoUVMaxAngle: 89 m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: -22961053 m_SortingLayerID: -22961053
m_SortingLayer: -1 m_SortingLayer: -2
m_SortingOrder: 0 m_SortingOrder: 0
m_Sprite: {fileID: 5854342148761561055, guid: 8cdb315d4968ef847a63e52bd8847e5b, type: 3} m_Sprite: {fileID: 5854342148761561055, guid: 8cdb315d4968ef847a63e52bd8847e5b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
@ -486,7 +486,7 @@ MonoBehaviour:
m_Intensity: 1 m_Intensity: 1
m_LightVolumeIntensity: 1 m_LightVolumeIntensity: 1
m_LightVolumeIntensityEnabled: 0 m_LightVolumeIntensityEnabled: 0
m_ApplyToSortingLayers: 0000000063a4a1fe m_ApplyToSortingLayers: 63a4a1fe7950b23d00000000
m_LightCookieSprite: {fileID: 0} m_LightCookieSprite: {fileID: 0}
m_DeprecatedPointLightCookieSprite: {fileID: 0} m_DeprecatedPointLightCookieSprite: {fileID: 0}
m_LightOrder: 0 m_LightOrder: 0
@ -730,7 +730,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3} - target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: -0.0487628 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3} - target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w

View File

@ -1,5 +1,48 @@
using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class ArtistController : MonoBehaviour { public class ArtistController : MonoBehaviour {
public int range = 50;
public int projectileSpeed = 5;
public GameObject projectile;
private Queue<GameObject> enemyQueue;
void Start() {
InvokeRepeating(nameof(fireAttack), 0, 1);
}
public void setEnemyQueue(Queue<GameObject> enemyQueueIn) {
enemyQueue = enemyQueueIn;
}
// Look through all of the queue, and find the distance between each enemy and the artist.
// Keep track of the enemy with the lowest distance, and after you have looped through the entire queue,
// Initiate a new instance of the projectile game object, from the artists position, in the direction of the enemy.
private void fireAttack() {
if (enemyQueue.Count == 0) return; // If there are no enemies in the queue, return.
if (enemyQueue.Peek() == null) return; // If the first enemy in the queue is null, return.
float lowestDistance = range;
GameObject enemyTarget = null;
foreach (var enemy in enemyQueue) {
var distance = Vector3.Distance(enemy.transform.position, transform.position);
if (distance < lowestDistance) {
lowestDistance = distance;
enemyTarget = enemy;
}
}
if (enemyTarget == null) return; // If there are no enemies in range, return.
//Find the vector that points from the artist to the enemy.
var heading = enemyTarget.transform.position - transform.position;
//Find the angle between the artist and the enemy.
var angle = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;
//Create a quaternion (rotation) based on the angle.
var q = Quaternion.Euler(0,0,angle);
var projectileInstance = Instantiate(projectile, transform.position, q);
projectileInstance.GetComponent<StandardProjectileController>().setSpeed(projectileSpeed);
}
} }

View File

@ -4,37 +4,43 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class GenerationController : MonoBehaviour { public class GenerationController : MonoBehaviour {
internal GameObject[] waypoints; public float speed;
private GameObject[] waypoints;
private int waypointIndex = 1; private int waypointIndex = 1;
private Rigidbody2D rb; private Rigidbody2D rb;
// Start is called before the first frame update
private void Start() { private void Start() {
rb = GetComponent<Rigidbody2D>(); rb = GetComponent<Rigidbody2D>();
} moveToNextWaypoint();
// Update is called once per frame
void Update() { }
private void FixedUpdate() {
if (waypointIndex < waypoints.Length) {
var target = waypoints[waypointIndex].transform.position;
var direction = target - transform.position;
var f = transform.position + direction.normalized * 0.1f;
rb.MovePosition(f);
} else if (waypointIndex >= waypoints.Length) {
Destroy(gameObject);
}
} }
private void OnTriggerEnter2D(Collider2D col) { private void OnTriggerEnter2D(Collider2D col) {
if (col.gameObject == waypoints[waypointIndex]) { if (col.gameObject == waypoints[waypointIndex]) {
waypointIndex++; waypointIndex++;
moveToNextWaypoint();
} }
} }
public void setWaypoints(GameObject[] waypointsIn) { public void setWaypoints(GameObject[] waypointsIn) {
waypoints = waypointsIn; waypoints = waypointsIn;
} }
private void moveToNextWaypoint() {
if (waypointIndex < waypoints.Length) {
// Point towards the next waypoint
var heading = waypoints[waypointIndex].transform.position - transform.position;
var distance = heading.magnitude;
var direction = heading / distance;
var angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
var q = Quaternion.Euler(0,0,angle);
transform.rotation = q;
//Move towards the next waypoint, taking into account the speed variable
rb.velocity = direction * speed;
} else if (waypointIndex >= waypoints.Length) {
Destroy(gameObject);
}
}
} }

View File

@ -18,7 +18,8 @@ public class LevelController : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update() { void Update() {
if (Input.GetMouseButtonDown(0)) { if (Input.GetMouseButtonDown(0)) {
Instantiate(artist, Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward, Quaternion.identity); var a = Instantiate(artist, Camera.main.ScreenToWorldPoint(Input.mousePosition) + (Vector3.forward * 10), Quaternion.identity);
a.GetComponent<ArtistController>().setEnemyQueue(enemies);
} }
} }

View File

@ -0,0 +1,27 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StandardProjectileController : MonoBehaviour {
private float speed;
private Rigidbody2D rb;
void Start() {
rb = GetComponent<Rigidbody2D>();
rb.velocity = transform.right * speed ;
}
void Update() {
}
public void setSpeed( float speedIn) {
speed = speedIn;
}
private void OnTriggerEnter2D(Collider2D col) {
Destroy(col.gameObject);
Destroy(gameObject);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7cdb7de3f3533494eae1b220ca0aebe1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -41,6 +41,9 @@ TagManager:
- name: Background - name: Background
uniqueID: 4272006243 uniqueID: 4272006243
locked: 0 locked: 0
- name: Attacks
uniqueID: 1035096185
locked: 0
- name: Default - name: Default
uniqueID: 0 uniqueID: 0
locked: 0 locked: 0