Commit 1d62e240 authored by Andrew's avatar Andrew

EnemyRanged determines to shoot you within a certain distance then draws a Debug.DrawLine

parent 5f74a86d
......@@ -6134,5 +6134,45 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3032704036229314206, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: moveSpeed
value: 2
objectReference: {fileID: 0}
- target: {fileID: 3032704036229314206, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: moveDecisionThreshold
value: 5
objectReference: {fileID: 0}
- target: {fileID: 3032704036229314206, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: teleportDecisionThreshold
value: 15
objectReference: {fileID: 0}
- target: {fileID: 546435855955265260, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: m_IsKinematic
value: 0
objectReference: {fileID: 0}
- target: {fileID: 546435855955265260, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: m_UseGravity
value: 1
objectReference: {fileID: 0}
- target: {fileID: 546435855955265260, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: m_Mass
value: 10000
objectReference: {fileID: 0}
- target: {fileID: 546435855955265260, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: m_Drag
value: 10000
objectReference: {fileID: 0}
- target: {fileID: 546435855955265260, guid: 5a907769260b22e499f65391b4d07926,
type: 3}
propertyPath: m_AngularDrag
value: 10000
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5a907769260b22e499f65391b4d07926, type: 3}
......@@ -19,11 +19,14 @@ public class EnemyRanged : MonoBehaviour
public GameObject ammoPrefab;
public float insanityRefillAmount;
public float chanceToDropAmmo;
[Space(5)]
float timer = 0;
[Header("Automatically-Set Values")]
[SerializeField] private GameObject player;
public Vector3 playerPosition;
public Transform thisTransform;
public float distanceToPlayer;
/// <summary>
/// Unity calls this function once before Start() (or as soon as a GameObject is made active).
......@@ -68,30 +71,44 @@ public class EnemyRanged : MonoBehaviour
void DecideToMove()
{
// Call this function every frame to compare distance from Player before choosing to Move(), Aim(), as well as Teleport().
// "Vector3.Distance" or "(vector_A - vector_B).magnitude" to get distance between two Transforms
if (Vector3.Distance(player.transform.position, this.transform.position) > teleportDecisionThreshold)
distanceToPlayer = Vector3.Distance(player.transform.position, this.transform.position);
// Call this function every frame to compare distance from Player before choosing to Move(), Aim(), as well as Teleport().
// "Vector3.Distance" or "(vector_A - vector_B).magnitude" to get distance between two Transforms
if (distanceToPlayer > teleportDecisionThreshold)
{
Teleport();
}
else if (Vector3.Distance(player.transform.position, this.transform.position) > moveDecisionThreshold)
else if (distanceToPlayer > moveDecisionThreshold)
{
Move();
}
}
if (distanceToPlayer <= moveDecisionThreshold + 1 && distanceToPlayer >= moveDecisionThreshold - 1)
{
Aim();
}
}
void Move()
{
// Call this function if EnemyRanged has decided to move towards the Player.
// Various ways to do this, such as "Vector3.MoveTowards" or "Vector3.Lerp"
this.transform.position = Vector3.MoveTowards(this.transform.position, player.transform.position, moveSpeed * Time.deltaTime);
// Call this function if EnemyRanged has decided to move towards the Player.
// Various ways to do this, such as "Vector3.MoveTowards" or "Vector3.Lerp"
Vector3 playerNoY = new Vector3 (player.transform.position.x, this.transform.position.y, player.transform.position.z);
this.transform.position = Vector3.MoveTowards(this.transform.position, playerNoY, moveSpeed * Time.deltaTime);
Debug.Log(this.name + " is moving!");
}
void Teleport()
{
// Call this function if Player is over "teleportDecisionThreshold" distance away from EnemyRanged.
this.transform.position = Vector3.MoveTowards(this.transform.position, player.transform.position, moveSpeed);
// Call this function if Player is over "teleportDecisionThreshold" distance away from EnemyRanged.
Vector3 playerNoY = new Vector3(player.transform.position.x, this.transform.position.y, player.transform.position.z);
this.transform.position = Vector3.MoveTowards(this.transform.position, playerNoY, moveSpeed);
Debug.Log(this.name + " teleported!");
}
#endregion
......@@ -103,6 +120,22 @@ public class EnemyRanged : MonoBehaviour
// Call this function right before firing to return a direction that the Enemy will shoot towards.
// If we let the Aim() change as "playerPosition" changes, the bullets will hone in on Player. We want to grab "playerPosition" at one specific point in time.
timer += Time.deltaTime;
if (timer > 3f)
{
Debug.Log("bang!");
Vector3 currentPlayerPosition = player.transform.position;
Color rand = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
Debug.DrawLine(this.transform.position, currentPlayerPosition, rand, 10f);
timer = 0;
}
Debug.Log(this.name + " is aiming!");
}
void ShootBullet()
......@@ -116,6 +149,11 @@ public class EnemyRanged : MonoBehaviour
#endregion
#region health
void TakeDamage()
{
// take damage!
}
void CheckHealth()
{
// Call this function every frame for conditionals based on remaining health, such as Die().
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment