Add ranged enemy

This commit is contained in:
Jens Pitkänen 2019-08-18 21:32:07 +03:00
parent a2d1096764
commit 163e09d58a
14 changed files with 10395 additions and 12 deletions

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -103,7 +103,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 978bec54408eb8f42a36fd68d7447f5a, type: 3}
m_Name:
m_EditorClassIdentifier:
Movement: {fileID: 4248768674552437703}
BehaviourDisplay: {fileID: 8912829886182716132}
CurrentBehaviour: Nothing
--- !u!114 &3068808787720623988
@ -136,7 +135,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3}
m_Name:
m_EditorClassIdentifier:
Body: {fileID: 592487110401094195}
Bobbing: {fileID: 3068808787720623988}
Direction: {x: 0, y: 0}
MaxSpeed: 2.5
@ -240,7 +238,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
CurrentStatus:
WalkingDistance: 2
MaxWalkingDistance: 2
MinWalkingDistance: 1
SubjectRadius: 0.7
StopLength: 2

View File

@ -0,0 +1,456 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &738167044357067052
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8421448882146741787}
- component: {fileID: 4848125059538075066}
m_Layer: 0
m_Name: Placeholder Sprite
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8421448882146741787
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738167044357067052}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.75, y: 1.75, z: 1}
m_Children: []
m_Father: {fileID: 6460565228684706449}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &4848125059538075066
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738167044357067052}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, 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: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: -947994997
m_SortingLayer: 4
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 472874229c563e241bddc073ec2dbb90, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.5, y: 0.5}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &2543259950034594903
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2738488192438041495}
- component: {fileID: 227033201631701465}
- component: {fileID: 6472150569122265160}
m_Layer: 0
m_Name: Behaviour Display
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &2738488192438041495
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2543259950034594903}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: 0}
m_LocalScale: {x: 0.15, y: 0.15, z: 0.15}
m_Children: []
m_Father: {fileID: 2690120730931629368}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &227033201631701465
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2543259950034594903}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10100, guid: 0000000000000000e000000000000000, 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!102 &6472150569122265160
TextMesh:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2543259950034594903}
m_Text: Hello World
m_OffsetZ: 0
m_CharacterSize: 1
m_LineSpacing: 1
m_Anchor: 7
m_Alignment: 0
m_TabSize: 4
m_FontSize: 0
m_FontStyle: 0
m_RichText: 1
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_Color:
serializedVersion: 2
rgba: 4294967295
--- !u!1 &2690120730931629369
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2690120730931629368}
- component: {fileID: 4766673605832234110}
- component: {fileID: 6622851958837894017}
- component: {fileID: 1250534548261569402}
- component: {fileID: 6575270342303945011}
- component: {fileID: 4069445145596408170}
- component: {fileID: 5458726275277878114}
- component: {fileID: 4655711410523782340}
- component: {fileID: 2365918186454816021}
- component: {fileID: 882638086997911926}
- component: {fileID: 7175095611357057067}
- component: {fileID: 7974156166935930478}
- component: {fileID: 8315503502695128381}
m_Layer: 0
m_Name: Enemy (Ranged - Name TBD)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2690120730931629368
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 6460565228684706449}
- {fileID: 2738488192438041495}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &4766673605832234110
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_BodyType: 0
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: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!61 &6622851958837894017
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
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, 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: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &1250534548261569402
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 978bec54408eb8f42a36fd68d7447f5a, type: 3}
m_Name:
m_EditorClassIdentifier:
BehaviourDisplay: {fileID: 6472150569122265160}
CurrentBehaviour: Nothing
--- !u!114 &6575270342303945011
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e796ba4c6f7efc449a10ed13ee42e34f, type: 3}
m_Name:
m_EditorClassIdentifier:
BobbedTransform: {fileID: 6460565228684706449}
BobbingMultiplier: 1
BobbingGravity: 0.8
BobbingLaunchSpeed: 0.12
BobbingFrequency: 0
BobbingDirection: {x: 0, y: 1}
--- !u!114 &4069445145596408170
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3}
m_Name:
m_EditorClassIdentifier:
Bobbing: {fileID: 6575270342303945011}
Direction: {x: 0, y: 0}
MaxSpeed: 2.5
AccelerationSpeed: 10
DecelerationSpeed: 10
--- !u!114 &5458726275277878114
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a2110188365a59e4cb31d0e84789fbbd, type: 3}
m_Name:
m_EditorClassIdentifier:
BodypartPrefabs:
- {fileID: 90224928841595158, guid: ca8392322c2a18b48a39044f77780e06, type: 3}
DebugExplode: 0
ParticlesPerBodypart: 20
BodypartMinCount: 5
BodypartMaxCount: 10
DebrisType: 1
--- !u!114 &4655711410523782340
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7d43d0a4a6d1e2d46a74083bdecde13e, type: 3}
m_Name:
m_EditorClassIdentifier:
MaxHealth: 0
CurrentHealth: 0
--- !u!114 &2365918186454816021
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 173be6658a5fcba49b9b1f1c91fa5f33, type: 3}
m_Name:
m_EditorClassIdentifier:
Radius: 8
ForgetRadius: 10
ForgetTimer: 0.5
--- !u!114 &882638086997911926
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f7e23822f429fcc46a8fd9163e68f332, type: 3}
m_Name:
m_EditorClassIdentifier:
CurrentStatus:
Target: {fileID: 0}
CloseEnoughRadius: 4
TargetPositionUpdateFrequency: 10
--- !u!114 &7175095611357057067
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bf838f73fb74f0046a5b6a86994c54ed, type: 3}
m_Name:
m_EditorClassIdentifier:
CurrentStatus:
MaxWalkingDistance: 1.5
MinWalkingDistance: 1
SubjectRadius: 0.7
StopLength: 4
--- !u!114 &7974156166935930478
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ecf1d55e7bc41504da01517c13e40873, type: 3}
m_Name:
m_EditorClassIdentifier:
CurrentStatus:
BulletPrefab: {fileID: 4482402865533696886, guid: 3563e3248e4153841b75d8670129b2bb,
type: 3}
Range: 5
Cooldown: 1
--- !u!114 &8315503502695128381
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a7ad92c263d7d594286b8fc50b5b8fa7, type: 3}
m_Name:
m_EditorClassIdentifier:
Anim: {fileID: 0}
--- !u!1 &3991584792453052187
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6460565228684706449}
m_Layer: 0
m_Name: Bobbing Root
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6460565228684706449
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3991584792453052187}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 8421448882146741787}
m_Father: {fileID: 2690120730931629368}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

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

View File

@ -8,8 +8,9 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
public float CloseEnoughRadius;
public float TargetPositionUpdateFrequency = 5f;
public Vector2 TargetDirection { private set; get; }
private Enemy Enemy;
private Vector2 TargetDirection;
private float TargetPositionUpdateCooldown;
private void Start() {
@ -32,6 +33,10 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
TargetPositionUpdateCooldown = Mathf.Min(TargetPositionUpdateCooldown, 1.0f / freq);
}
public float GetDistance() {
return Target == null ? -1.0f : (Target.position - Enemy.transform.position).magnitude;
}
public override bool CanBehave() {
bool TargetExists = Target != null;
if (!TargetExists) {
@ -43,10 +48,8 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
public override void Execute() {
if (Target != null) {
Vector2 position = Enemy.transform.position;
Vector2 delta = (Vector2)Target.position - position;
if (delta.magnitude > CloseEnoughRadius) {
Enemy.StartMovingTo(position + TargetDirection);
if (GetDistance() > CloseEnoughRadius) {
Enemy.StartMovingTo((Vector2)Enemy.transform.position + TargetDirection);
CurrentStatus = "Approach";
} else {
Enemy.StopMoving();
@ -54,5 +57,10 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
}
}
}
private void OnDrawGizmosSelected() {
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, CloseEnoughRadius);
}
}
}

View File

@ -0,0 +1,53 @@
using UnityEngine;
using Saltosion.OneWeapon.Guns;
namespace Saltosion.OneWeapon.AI.Behaviours {
[RequireComponent(typeof(Follow))]
public class RangedAttackFollowed : AIBehaviour {
public GameObject BulletPrefab;
public float Range;
public float Cooldown;
public bool Attacking { get { return CanBehave(); } }
private Follow Follow;
private float CurrentCooldown;
private void Start() {
Follow = GetComponent<Follow>();
}
private void Update() {
if (CurrentCooldown > 0) {
CurrentCooldown -= Time.deltaTime;
}
}
public override bool CanBehave() {
return Follow.Target != null && Follow.GetDistance() <= Range;
}
public override void Execute() {
CurrentStatus = "PewPew";
if (CurrentCooldown <= 0) {
Shoot();
CurrentCooldown = Cooldown;
CurrentStatus = "PEW"; // A joke that lasts for a frame
}
}
private void Shoot() {
Vector2 Direction = Follow.TargetDirection;
GameObject ShotBulletObj = Instantiate(BulletPrefab, transform.position + (Vector3)Direction, new Quaternion());
Bullet ShotBullet = ShotBulletObj.GetComponent<Bullet>();
ShotBullet.Direction = Direction.normalized;
ShotBullet.InitialRotation = Mathf.Atan2(Direction.y, Direction.x);
}
private void OnDrawGizmosSelected() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, Range);
}
}
}

View File

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

View File

@ -4,7 +4,7 @@ using Saltosion.OneWeapon.Enemies;
namespace Saltosion.OneWeapon.AI.Behaviours {
[RequireComponent(typeof(Enemy))]
public class Wander : AIBehaviour {
public float WalkingDistance;
public float MaxWalkingDistance;
public float MinWalkingDistance;
public float SubjectRadius;
public float StopLength;
@ -45,7 +45,7 @@ namespace Saltosion.OneWeapon.AI.Behaviours {
Debug.LogWarning($"Wander behaviour took over 100 tries to find a wander position, '{Enemy.name}' is stuck!");
break;
}
float Distance = MinWalkingDistance + (WalkingDistance - MinWalkingDistance) * Random.value;
float Distance = MinWalkingDistance + (MaxWalkingDistance - MinWalkingDistance) * Random.value;
float Direction = Random.value * Mathf.PI * 2f;
Vector2 Delta = new Vector2(Mathf.Cos(Direction), Mathf.Sin(Direction)) * Distance;
RaycastHit2D Hit = Physics2D.Raycast(SubjectPosition + Delta.normalized * SubjectRadius, Delta.normalized, Distance);

View File

@ -4,20 +4,22 @@ using Saltosion.OneWeapon.AI;
using Saltosion.OneWeapon.Utils;
namespace Saltosion.OneWeapon.Enemies {
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(Rigidbody2D), typeof(AcceleratedMovement))]
public class Enemy : MonoBehaviour {
private static Enemy latestDebugHoveredEnemy = null;
public AcceleratedMovement Movement;
[Header("Debug Info")]
public TextMesh BehaviourDisplay;
public string CurrentBehaviour = "Nothing";
public AcceleratedMovement Movement { private set; get; }
private Rigidbody2D Body;
private bool MovingToTarget = false;
private Vector2 TargetPosition;
private void Start() {
Movement = GetComponent<AcceleratedMovement>();
Body = GetComponent<Rigidbody2D>();
BehaviourDisplay.GetComponent<MeshRenderer>().sortingLayerName = "Debug Text";
}

View File

@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Saltosion.OneWeapon.AI.Behaviours;
using Saltosion.OneWeapon.AI.Triggers;
namespace Saltosion.OneWeapon.Enemies {
[RequireComponent(typeof(Enemy))]
[RequireComponent(typeof(PlayerSighted))]
[RequireComponent(typeof(Wander))]
[RequireComponent(typeof(Follow))]
[RequireComponent(typeof(RangedAttackFollowed))]
public class RangedNameTBD : MonoBehaviour {
public Animator Anim;
private Enemy Enemy;
private PlayerSighted FollowTrigger;
private Wander WanderBehaviour;
private Follow FollowBehaviour;
private RangedAttackFollowed RangedBehaviour;
private void Start() {
Enemy = GetComponent<Enemy>();
FollowTrigger = GetComponent<PlayerSighted>();
WanderBehaviour = GetComponent<Wander>();
FollowBehaviour = GetComponent<Follow>();
RangedBehaviour = GetComponent<RangedAttackFollowed>();
}
private void Update() {
Enemy.CurrentBehaviour = "";
if (FollowTrigger.IsTriggered()) {
FollowBehaviour.Target = FollowTrigger.Player.transform;
if (FollowBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Follow:" + FollowBehaviour.CurrentStatus + ", ";
}
if (RangedBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Ranged:" + RangedBehaviour.CurrentStatus;
}
} else if (WanderBehaviour.TryExecute()) {
Enemy.CurrentBehaviour += "Wander:" + WanderBehaviour.CurrentStatus;
}
// TODO: Add animation
//if (RangedBehaviour.Attacking) {
// Anim.Play("Attack");
//} else {
// Anim.Play("Walk");
//}
//Anim.SetFloat("Speed", Enemy.Movement.SpeedPercentage);
}
}
}

View File

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

View File

@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Saltosion.OneWeapon.Player;
using Saltosion.OneWeapon.Enemies;
using Saltosion.OneWeapon.Effects;
using Saltosion.OneWeapon.Environment;
namespace Saltosion.OneWeapon.Guns {
[RequireComponent(typeof(Bullet))]
public class EnemyBullet : MonoBehaviour {
public Rigidbody2D Body;
public GameObject Sprite;
public ParticleSystem Trail;
public ParticleSystem Explosion;
[Tooltip("This currently does not affect the Fun damage.")]
public float Damage = 12;
private float DeathTimer = 0;
private Bullet Bullet;
void Start() {
Bullet = GetComponent<Bullet>();
Vector2 Direction = Bullet.Direction;
float Rot = Bullet.InitialRotation;
Body.velocity = Direction * 15;
Body.rotation = Rot - 90;
Explosion.Stop();
}
void Update() {
DeathTimer += Time.deltaTime;
if (DeathTimer > 20) {
Destroy(gameObject);
}
}
void OnTriggerEnter2D(Collider2D collider) {
Bullet.HasExploded = true;
Destroy(Sprite);
Destroy(Body);
Destroy(GetComponent<CapsuleCollider2D>());
Explosion.Play();
Trail.Stop();
DeathTimer = 19;
// Do damage here, kill everyone
PlayerFun Player = collider.GetComponent<PlayerFun>();
Health OtherEnemyHealth = collider.GetComponent<Health>();
if (Player != null) {
Player.TakeDamage();
}
if (OtherEnemyHealth != null) {
OtherEnemyHealth.Damage(Damage, Bullet.Direction, false);
}
if (collider.tag == "Environment") {
DebrisLauncher.Splatter(DebrisType.Structural, transform.position, Bullet.Direction, 5, 30, 360);
}
if (collider.attachedRigidbody != null && collider.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) {
collider.attachedRigidbody.AddForce(Bullet.Direction * 4, ForceMode2D.Impulse);
}
}
}
}

View File

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