Skip to content

Commit

Permalink
Commit before i edit the enemyshipcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
Redtricity committed Apr 11, 2024
1 parent d82eacd commit ea64f6e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
Binary file modified .plastic/plastic.changes
Binary file not shown.
Binary file modified .plastic/plastic.wktree
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
using System.Collections.Generic;
using UnityEngine;

public partial class AIShipMovementControls : MovementControlsBase
public class AIShipMovementControls : MovementControlsBase
{

[SerializeField]
Transform _target;

Expand Down
30 changes: 23 additions & 7 deletions Assets/Code/Scripts/C#/ShipControls/EnemyShipController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum EnemyShipState
Transform _target;

public UnityEvent<int> ShipDestroyed = new UnityEvent<int>();

#region Public data for debugging

public string ShipState => _state.ToString();
Expand All @@ -43,12 +43,13 @@ public string DistanceToTarget
{
distance = $"{Vector3.Distance(_target.position, _transform.position):F2}";
}

return distance;
}
}

public string HealthLevel => $"{_damageHandler.Health}/{_damageHandler.MaxHealth}";

#endregion

bool InAttackRange => Vector3.Distance(PlayerShip.transform.position, _transform.position) <= _attackRange;
Expand Down Expand Up @@ -79,6 +80,11 @@ public override void Update()
EnemyShipState state = GetNextState();
SetState(state);
base.Update();

if (_state == EnemyShipState.Patrol || _state == EnemyShipState.Attack)
{
Debug.Log($"{_transform.name} is {_state} at distance {DistanceToTarget} to target {_target.name}");
}
}

EnemyShipState GetNextState()
Expand All @@ -89,21 +95,23 @@ EnemyShipState GetNextState()
EnemyShipState.Attack => Attack(),
EnemyShipState.Reposition => Reposition(),
EnemyShipState.Retreat => Retreat(),
_ => EnemyShipState.None
_ => EnemyShipState.None
};
return newState;
}

EnemyShipState Patrol()
{

if (ShouldRetreat) return EnemyShipState.Retreat;
if (InAttackRange) return EnemyShipState.Attack;
if (ReachedPatrolTarget)
{
_target.position = Random.insideUnitSphere * _patrolRange;
}

return EnemyShipState.Patrol;

}

EnemyShipState Attack()
Expand All @@ -128,6 +136,9 @@ EnemyShipState Retreat()
void SetState(EnemyShipState state)
{
if (_state == state) return;

Debug.Log($"State Change: {_transform.name} from {_state} to {state} at position {_transform.position}");

_state = state;
switch (state)
{
Expand All @@ -137,7 +148,10 @@ void SetState(EnemyShipState state)
_target = new GameObject("Patrol Target").transform;
_target.position = Random.insideUnitSphere * _patrolRange;
_aiShipMovementControls.SetTarget(_target);

Debug.Log("Patrol Target Set: " + _target.position);
}

break;
case EnemyShipState.Attack:
if (_target)
Expand All @@ -148,6 +162,9 @@ void SetState(EnemyShipState state)
_target = PlayerShip.transform;
_aiShipMovementControls.SetTarget(_target);
SetWeaponsTarget(_target, _attackRange, _targetMask);

Debug.Log($"{_transform.name} has the player in attack range at distance {Vector3.Distance(PlayerShip.transform.position, _transform.position)}");
Debug.Log("Attacking Player Ship: " + _target.name);
break;
case EnemyShipState.Reposition:
_aiShipMovementControls.SetTarget(_target = GetRepositionTarget());
Expand All @@ -156,6 +173,7 @@ void SetState(EnemyShipState state)
case EnemyShipState.Retreat:
_aiShipMovementControls.SetTarget(_target = GetRetreatTarget());
SetWeaponsTarget(null, 0, 0);
Debug.Log($"{_transform.name} is retreating due to low health at position {_transform.position}");
break;
}
}
Expand Down Expand Up @@ -185,12 +203,10 @@ Transform GetRepositionTarget()
target.position = _transform.position + direction * 250f;
return target;
}



void SetWeaponsTarget(Transform target, float attackRange, int targetMask)
{

_aiShipWeaponControls.SetTarget(_target, attackRange, targetMask);
}

}
8 changes: 4 additions & 4 deletions Assets/Data/Enemy.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d396a6ee1e4e80b41a70d0299db4f176, type: 3}
m_Name: Enemy
m_EditorClassIdentifier:
_thrustForce: 1000
_pitchForce: 1384
_thrustForce: 7000
_pitchForce: 1400
_rollForce: 1000
_yawForce: 1861
_yawForce: 1200
_shieldStrength: 100
_shieldRegenAmount: 100
_maxHealth: 100
_blasterDamage: 50
_blasterDamage: 100
_blasterLaunchForce: 7500
_blasterCoolDown: 1
_blasterProjectileDuration: 3
2 changes: 1 addition & 1 deletion Assets/Data/EscortFighter.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d396a6ee1e4e80b41a70d0299db4f176, type: 3}
m_Name: EscortFighter
m_EditorClassIdentifier:
_thrustForce: 7555
_thrustForce: 9000
_pitchForce: 2000
_rollForce: 1000
_yawForce: 2000
Expand Down
13 changes: 12 additions & 1 deletion Assets/Level/Prefabs/Ship/EnemyShip.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -4917,7 +4917,7 @@ Transform:
serializedVersion: 2
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_LocalScale: {x: 2.1972837, y: 2.1972837, z: 2.1972837}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2094068067535200792}
Expand Down Expand Up @@ -10905,6 +10905,17 @@ PrefabInstance:
propertyPath: m_Name
value: AIShipMovementControls
objectReference: {fileID: 0}
- target: {fileID: 8898876503513727776, guid: 1577e5dd8241208448dca18d6f6cc369,
type: 3}
propertyPath: _target
value:
objectReference: {fileID: 6124476701410091073, guid: e6f3b60206ee26a46b6a1ca0a1f2d189,
type: 3}
- target: {fileID: 8987843823871055711, guid: 1577e5dd8241208448dca18d6f6cc369,
type: 3}
propertyPath: _layerMask.m_Bits
value: 4672
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 3228480935814066361, guid: 1577e5dd8241208448dca18d6f6cc369, type: 3}
m_RemovedGameObjects: []
Expand Down

0 comments on commit ea64f6e

Please sign in to comment.