I am working on a simple melee attack mechanic but I noticed that no matter what speed I set the knockback to, it always seems like the character just instantly moves back instead of smoothly doing it. Is there a way to make it so I can keep the speed in which the knockback is applied but see the character "slide" back instead of teleporting back? Here is the code I'm using:
public class meleeAttack : MonoBehaviour
{
int speed = 1000;
void Start()
{
}
void Update()
{
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player" && Input.GetKeyUp(KeyCode.F))
{
other.GetComponent().AddForce(transform.forward * speed);
}
}
}
↧