mirror of
https://github.com/ConjureETS/EscapeTheRoom.git
synced 2026-03-24 01:00:58 +00:00
bug fix
This commit is contained in:
parent
0e3f27ef91
commit
154db088c2
@ -4,37 +4,47 @@ using System.Collections;
|
|||||||
public class monsterAI : MonoBehaviour
|
public class monsterAI : MonoBehaviour
|
||||||
{
|
{
|
||||||
public GameObject player;
|
public GameObject player;
|
||||||
private Transform target = player.transform;
|
private Transform target;
|
||||||
public float deadlyDistance;
|
public float deadlyDistance;
|
||||||
public float rotationDamping;
|
public float rotationDamping; // Lower rotation damping = slower rotation
|
||||||
|
public float moveSpeed;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start ()
|
void Start ()
|
||||||
{
|
{
|
||||||
|
target = player.transform;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update ()
|
void Update ()
|
||||||
{
|
{
|
||||||
|
if (IsAtDeadlyDistance ()) {
|
||||||
|
// Kill the player
|
||||||
|
} else {
|
||||||
|
LookAtTarget ();
|
||||||
|
MoveTowardTarget ();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check is the current distance is deadly for the target
|
// Check is the current distance is deadly for the target
|
||||||
bool IsAtDeadlyDistance () {
|
bool IsAtDeadlyDistance ()
|
||||||
return (deadlyDistance <= Vector3.Distance(target.position, transform.position);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Follow player from a certain initial distance at a certain speed.
|
|
||||||
void FollowTarget ()
|
|
||||||
{
|
{
|
||||||
|
return (deadlyDistance <= Vector3.Distance (target.position, transform.position));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look toward target
|
// Look toward target
|
||||||
void LookAtTarget () {
|
void LookAtTarget ()
|
||||||
Quaternion rotation = Quaternion.LookRotation (target.rotation - transform.rotation);
|
{
|
||||||
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping);
|
//Quaternion rotation = Quaternion.LookRotation (target.rotation - transform.rotation);
|
||||||
|
//transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Follow player from a certain initial distance at a certain speed.
|
||||||
|
void MoveTowardTarget ()
|
||||||
|
{
|
||||||
|
transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user