im woking on a 2d fighter game and since im a amateur I searched around on the internet after a punching script that would send the reciving player flying away the oposite way.
So i found this script but it only freezes the punching player for a split second and i cant tell why.
here is the script:
using UnityEngine;
using System.Collections;
public class playerknocokback : MonoBehaviour {
// Use this for initialization
void Start () {
}
bool dopunch;
// Update is called once per frame
void Update () {
if (!dopunch && Input.GetKeyDown(KeyCode.DownArrow))
{
StartCoroutine(Punch(0.5f, 1.25f, transform.forward));
}
}
IEnumerator Punch(float time, float distance, Vector3 direction)
{
dopunch = true;
var timer = 0.0f;
var orgpos = transform.position;
direction.Normalize();
while (timer <= time)
{
Debug.Log(ā----ā);
transform.position = orgpos + (Mathf.Sin(timer / time * Mathf.PI) + 1.0f) * direction;
yield return null;
timer += Time.deltaTime;
}
transform.position = orgpos;
dopunch = false;
}
}