- Home /
AddForce not working in Coroutine
In a game I am making I have a code that after a short scene between the main character and the bad guy it is supposed to launch the player to a small island to the side where the first boss will spawn I made a function with AddForce and placed it into the coroutine that controlled the cutscene but instead of launching the player into the air and to the side once landing them on the island it launches the player into infinity. how do I fix this? here is the code.
IEnumerator HitLog()
{
playerStop = true;
PlayerAnimator.SetBool("Right Run Trig", false);
yield return new WaitForSeconds(1);
wordBubble.SetActive(true);
yield return new WaitForSeconds(8);
magician.SetActive(true);
magic.SetBool("poof left", true);
yield return new WaitForSeconds(8);
wordBubble.transform.position = new
Vector3(wordBubble.transform.position.x,
wordBubble.transform.position.y, -1000);
yield return new WaitForSeconds(3);
//where it launches the player.
LaunchPlayer(-1, 1);
yield return new WaitForSeconds(0.5f);
playerStop = false;
yield break;
}
private void LaunchPlayer(float x, float y)
{
// theplayerlaunch function
TargetRb.AddForce(new Vector2(x, y) * 0.5f, ForceMode2D.Impulse);
}
Comment
my booleans also glich out in the function like playerstop keeps turing on and off really fast and going crazy and I have no idea why please help me.
Your answer
