projectile affected by parent object

Hey,

I’ve been playing around with 2d game and have projectile/bullet firing from the player character. However when I jump and fire at the same time the momentum of the parent object jumping is causing my projectile to go off an and angle.

Is there anyway to modify this so that the bullet will only ever have force applied to it on the x-axis?

This is the current script for firing the projectile this is attached to an object who’s parent is the player

public void Fire(bool isFacingRight) 
{
	var clone = 
		this.Instantiate(this.ProjectilePrefab, transform.position, transform.rotation) as GameObject;
	
	var direction = isFacingRight ? 1 : -1;
	clone.transform.localScale *= direction;
		
	clone.rigidbody2D.AddForce(new Vector2(this.ProjectileSpeed * direction, 0));
}

You can add an empty gameobject in front of your gun, enough so that it doesn’t hit the collider and use that to shoot from. Bullet/projectile shouldn’t have gravity on.

You can try and setup some scheme to ignore either the layer your player is on or check the game object tag/name during collision and ignore if it’s the player.

Oooorr, you can use Raycasting, but this might be a little funky in 2d