Whats up my Unity Fam I have this player moving script that includes a dash method.
void Start()
{
rigidbody2d = GetComponent<Rigidbody2D>();
float distanceToClosestEnemy = Mathf.Infinity;
Enemy closestEnemy = null;
Enemy[] allEnemies = GameObject.FindObjectsOfType<Enemy>();
weaponaiming = GetComponent<WeaponAiming>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (dashCounter == 0)
{
Vector2 direction = new Vector2(movementjoystick.joystickVec.x, movementjoystick.joystickVec.y);
StartCoroutine(Dash(dashTime, dashSpeed, direction));
}
}
}
void FixedUpdate()
{
if (canMove)
{
if (movementjoystick.joystickVec.y != 0)
{
rigidbody2d.velocity = new Vector2(movementjoystick.joystickVec.x * speed, movementjoystick.joystickVec.y * speed);
}
else
{
rigidbody2d.velocity = Vector2.zero;
}
}
}
public IEnumerator Dash (float dashDuration, float dashPower, Vector2 dashDirection)
{
float timer = 0;
canMove = false;
while (dashDuration > timer)
{h")
timer += Time.deltaTime;
rigidbody2d.AddForce(dashDirection * dashPower);
}
canMove = true;
yield return 0;
}
However when the dash method is called the player just teleports instead of getting pushed. help