I’ve looked at lots of examples and really can’t see what I’m doing differently… but when I use AddForce to have a ball get kicked in the direction the player’s character is facing, it only ever goes in one direction regardless of which way they are facing. Here’s what I’m doing in my character movement script:
if (move > 0) {
LastFacingRight = true;
}else if (move < 0){
LastFacingRight = false;
}
if (shoot && hasBall && ball != null) {
ball.isKinematic = false;
ball.transform.SetParent(null);
ball.transform.localScale = new Vector2(1,1);
ball.GetComponent<CircleCollider2D>().enabled =true;
if (LastFacingRight) {
ball.AddForce(new Vector2(500f, 500f));
}else{
ball.AddForce(new Vector2(-500f, 500f));
}
hasBall = false;
ball = null;
}
If the player is facing right, the ball gets kicked out with a decent force upwards and to the right as expected, but if they are facing left the ball just gets dropped on the spot.
I’ve put a breakpoint at the start and stepped through and I can see the LastFacingRight variable is working as expected and if the player is facing left then this line with the negative x axis force does indeed get executed:
ball.AddForce(new Vector2(-500f, 500f));
I have tried all sorts of different things that I’ve seen other people recommend, like using this instead:
ball.AddForce(-Vector2.right * 500f));
But same end result… always works when facing right but never when facing left.