I wrote a script that make enemy to be pushed out when collision with weapon but it might not working well. This is my idea:
I want when enemy touch the blade, it will move slowly from B to C but my script make it move from B to C immediately.
Here is my code
public class bat_controller : MonoBehaviour {
public Transform hero;
public float distance;
private void Awake()
{
hero = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update () {
direction = (hero.position - transform.position).normalized;
private void OnTriggerEnter2D(Collider2D col)
{
if (col.CompareTag("blade"))
{
if (!ishurt)
{
Vector3 startpos = transform.position;
Vector3 endpos = startpos + (-movedir * distance);
transform.position = Vector3.Lerp(startpos, endpos, 3*Time.deltaTime);
}
}
}
}
and sorry for my English :