Hi everyone,
Currently I am making a 2D top down shooter game and I am trying to get the actual shooting mechanic to work. The player moves with WASD and the mouse controls the forward of the player. Then if the player presses “space” a bullet is instantiated at the players forward and would ideally be shot. However currently the bullet spawns, but it does not move. Here is my code:
Vector2 direction = ((mouse - transform.position));
public int bulletSpeed;
direction.Normalize();
if (Input.GetKeyDown(KeyCode.Space))
{
GameObject projectile = Instantiate(bulletObject, transform.position + (Vector3)(direction * 0.5f), Quaternion.identity);
projectile.GetComponent<Rigidbody2D>().AddForce(projectile.transform.forward * bulletSpeed, ForceMode2D.Impulse);
}
I am trying to add force to the bullet one it is spawned but currently it does not do anything. Any help would be greatly appreciated.