using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Boar : MonoBehaviour
{
public Transform player;
public Transform boar;
private Vector2 attackDirection;
private float aggroMagnitude;
private float aggroRange;
// Start is called before the first frame update
void Start()
{
aggroRange = 6;
}
// Update is called once per frame
void Update()
{
if(Vector2.Distance(player.transform.position,boar.transform.position) < aggroRange)
{
attackDirection = new Vector2(player.position.x - boar.position.x, player.position.y - boar.position.y);
aggroMagnitude = 0.075f / attackDirection.magnitude;
if (aggroMagnitude > 0.075f)
{
aggroMagnitude = 0.075f;
}
attackDirection = Vector2.ClampMagnitude(attackDirection, aggroMagnitude);
boar.Translate(attackDirection);
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Boar : MonoBehaviour { public Transform player; public Transform boar; private Vector2 attackDirection; private float aggroMagnitude; private float aggroRange; // Start is called before the first frame update void Start() { aggroRange = 6; }
}