Game Object is moving towards the left when fire button is pressed.

I’m currently making a Space Invader clone as a practice I used Rigidbody on the ship. The problem that I’m getting is whenever I pressed the fire button the Ship moves towards the left every time it shoots. Choosing Kinematic fixes this, however this ignores the box collider that I placed on to act as a border for the ship.

I know that there are better ways to execute this properly but I’m currently experimenting if there is a way to remove the force.

My question is how can I remove the force being added to the ship?


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ship_control : MonoBehaviour
    public float moveSpeed;
    private Rigidbody2D ship;

    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;

    private float nextFire;

    // Start is called before the first frame update
    void Start()
        ship = GetComponent<Rigidbody2D>();

    // Update is called once per frame
    void Update()
        if (Input.GetAxisRaw("Horizontal")>0.5f||Input.GetAxisRaw("Horizontal")<-0.5)
            ship.velocity = new Vector2 (Input.GetAxisRaw("Horizontal") * moveSpeed, ship.velocity.y);

        if (Input.GetAxisRaw("Horizontal")<0.5f&&Input.GetAxisRaw("Horizontal")>-0.5)
            ship.velocity = new Vector2(0f, ship.velocity.y);

        if (Input.GetButton("Fire1")&&Time.time>nextFire)
            nextFire = Time.time + fireRate;



Does your projectile spawn inside the collider of the ship?? Try offsetting the spawn position a bit or scaling down the ship’s collider

Make sure your not spawning the bullet inside the ship’s collider.
saying that youre spawning at a spawnshot gameobject’s location, move spawnshot out of the collider of the ship