In my game each player has a shootpoint so the game knows where I want the bullet to be spawned, but I encountered some problems.
Every time when player 1 joins, it spawns a bullet at the spawn location of player 1 and the shootpoint. When player 2 spawns and shoots, the bullet only spawns from the shootpoint. Both player 1 and 2 use the same script. Here is my code:
public void Shoot(InputAction.CallbackContext context){
Instantiate(Bullet, shootpoint.position, shootpoint.rotation);
if(gameObject.transform.rotation.eulerAngles.y == -180){
Bullet.gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.left * force;
} else if(gameObject.transform.rotation.eulerAngles.y == 0){
Bullet.gameObject.GetComponent<Rigidbody2D>().velocity = Vector2.right * force;
}
}
As you can see I am using the new inputsystem and I am also trying to make the bullet fly a little, you know like a real bullet… In the beginning I did it with 2 separate scripts but I think it’s better if I do it with 1 script.
Does anyone know how to fix that bug and/or make the bullet fly?