player movement not working well after Clash whit enemy, after colliding whit enemy for few secs he stop follow the mouse correctly
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playermovment : MonoBehaviour
{
[SerializeField]
float MoveSpeed = 0.34f;
Vector2 MouseInWorld;
void Start()
{
}
// Update is called once per frame
void Update()
{
MouseInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = Vector3.Lerp(transform.position, MouseInWorld, MoveSpeed);
}
}
and this is the enemy movment (this keep work ,this follow the player)
float distance = Vector3.Distance(player.position, transform.position);
Vector3 direction = player.position - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
rb.rotation = angle;
direction.Normalize();
movement = direction;