Help with attack of the enemy
I have a code when the enemy attacks the player The enemy advances forward gives a blow to the player and the girl returns but I have a problem that the enemy gives the blow but does not reach the player only close to him
the code
void Update()
{
Attack();
}
void Attack()
{
spasBetweenAttackToAttack += 1 * Time.deltaTime;
if (Vector2.Distance(rb.transform.position, player.transform.position) < 4 && spasBetweenAttackToAttack >= 2f)
{
spasBetweenAttackToAttack = 0f;
rb.transform.position = Vector2.Lerp(rb.transform.position, player.transform.position, 0.3f);
}
}
The little square is the enemy
h.png
(2.1 kB)
Comment
Your answer
Follow this Question
Related Questions
Problem with Vector2/Vector3.Angle? 0 Answers
How to make a retracting Tongue? 0 Answers
2d cannon projectile not following expected path 1 Answer
Get angle between a position and facing direction 0 Answers
Vector question 0 Answers