- Home /
Question by
crazy_ted · Nov 29, 2018 at 02:34 AM ·
2d sprites2d rotation2dmovement
How to get a sprite to move in the direction it is facing .
I am creating a game where a player in the middle of the screen rotates and fires a gun at enemies coming at him from the edges. I am trying to get the bullet when fired to move in the direction it is facing.
This is only moving the Z axis.
public class BulletMovement : MonoBehaviour {
public float moveSpeed;
private void FixedUpdate()
{
transform.position += transform.forward * Time.deltaTime * moveSpeed;
}
}
Comment
Best Answer
Answer by Vega4Life · Nov 29, 2018 at 03:16 AM
Instead of transform.forward, try transform.right. But, you will have to negate it if you are doing -Scale on the x to get the sprite to look the other way.
That's why you see a lot of bools of 'isFacingRight' with 2D sprites.
Your answer
