Zombies fertig
This commit is contained in:
@ -20,11 +20,15 @@ public class Zombie : MonoBehaviour
|
||||
[SerializeField]
|
||||
private float _attackRange = 1.3f;
|
||||
[SerializeField]
|
||||
private float _jumpForce;
|
||||
[SerializeField]
|
||||
private float _idleThresholdFactor = 0.2f;
|
||||
[SerializeField]
|
||||
private float _noiseDelay = 5.0f;
|
||||
[SerializeField, ShowOnly]
|
||||
private float _noiseTimer;
|
||||
[SerializeField]
|
||||
private LayerMask _groundLayer;
|
||||
|
||||
private Rigidbody _rb;
|
||||
private AudioSource _audioSource;
|
||||
@ -32,7 +36,7 @@ public class Zombie : MonoBehaviour
|
||||
private Animator _animator;
|
||||
private bool _isAttacking = false;
|
||||
private float _idleThreshold;
|
||||
private Quaternion _initialRotation;
|
||||
private Vector3 _initialPosition;
|
||||
|
||||
|
||||
|
||||
@ -49,7 +53,7 @@ public class Zombie : MonoBehaviour
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_idleThreshold = _speed / _idleThresholdFactor;
|
||||
_initialRotation = transform.rotation;
|
||||
_initialPosition = transform.position;
|
||||
}
|
||||
|
||||
void Update()
|
||||
@ -67,8 +71,9 @@ void Update()
|
||||
{
|
||||
Vector3 direction = (GameManager.Instance.Player.transform.position - transform.position);
|
||||
Quaternion goalRotation = Quaternion.LookRotation(direction);
|
||||
transform.rotation = Quaternion.RotateTowards(transform.rotation, goalRotation, _rotateSpeed * Time.deltaTime);
|
||||
transform.rotation = Quaternion.Euler(0, Quaternion.RotateTowards(transform.rotation, goalRotation, _rotateSpeed * Time.deltaTime).eulerAngles.y, 0);
|
||||
float diff = direction.magnitude;
|
||||
//Debug.Log(diff);
|
||||
if (diff <= _attackRange && !_isAttacking)
|
||||
{
|
||||
_animator.SetFloat("Running", 0);
|
||||
@ -78,12 +83,21 @@ void Update()
|
||||
else
|
||||
{
|
||||
Vector3 oldPosition = _rb.position;
|
||||
_rb.MovePosition(_rb.position + direction * _speed * Time.deltaTime);
|
||||
Vector3 goalDirection = new Vector3(direction.x, 0.2f, direction.z);
|
||||
if (Physics.Raycast(transform.position + new Vector3(0, 0.1f, 0), goalDirection, 1f, _groundLayer))
|
||||
{
|
||||
Debug.Log("RayCast HIT");
|
||||
//_rb.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse);
|
||||
_rb.MovePosition(_rb.position - transform.forward * Time.deltaTime);
|
||||
_rb.MovePosition(_rb.position + new Vector3(0, _jumpForce, 0) * Time.deltaTime);
|
||||
}
|
||||
_rb.MovePosition(_rb.position + goalDirection * _speed * Time.deltaTime);
|
||||
float dist = Vector3.Distance(oldPosition, _rb.position);
|
||||
//Debug.Log($"Distance: {dist}, Threshold: {_idleThreshold * Time.deltaTime}");
|
||||
if (dist > _idleThreshold * Time.deltaTime)
|
||||
{
|
||||
_animator.SetBool("Idle", false);
|
||||
_animator.SetFloat("Running", 1);
|
||||
_animator.SetFloat("Running", _speed * 3.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -97,12 +111,12 @@ void Update()
|
||||
{
|
||||
_isAttacking = true;
|
||||
_animator.SetBool("Attack", true);
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
_animator.SetBool("Attack", false);
|
||||
// check if actually hit
|
||||
Vector3 direction = (GameManager.Instance.Player.transform.position - transform.position);
|
||||
float diff = direction.magnitude;
|
||||
if (diff <= _attackRange + 0.5f)
|
||||
if (diff <= _attackRange + 0.6f)
|
||||
{
|
||||
GameManager.Instance.Player.GetComponent<Character>().PickupItem(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user