Shooting a rigidbody straight?

Hi, i’m new to the forums and i have a problem shooting a rigidbody. Full story:

I’m making a test game with a space ship wich is a rigidbody and this ship shoots other rigidbodies as projectiles. Everything is perfect but the projectiles are supposed to be laser beams so i don’t want that they make an angle when i’m shooting and i’m turning the ship at the same time so my question is if there is a way to make a rigidbody react only to a force in one axis (so they keep straight forward) or is there another better way to shoot projectiles than this one.

Here is my code and a pair of pictures so you can understand what i’m trying to say:

	void FixedUpdate () {
                //The impulse of the ship
		rigidbody.velocity = transform.TransformDirection(new Vector3(currentVelocity, 0.0f, 0.0f));

		//Fire the guns
		GameObject LGun = GameObject.Find("LGun"); 
		GameObject RGun = GameObject.Find("RGun");
		if (Input.GetButton ("Fire1")  Time.time > nextFire) {
			nextFire = Time.time + fireRate;
			Rigidbody lBeam = Instantiate (projectile, LGun.transform.position, LGun.transform.rotation) as Rigidbody;
			Rigidbody RBeam = Instantiate (projectile, RGun.transform.position, RGun.transform.rotation) as Rigidbody;
			lBeam.velocity = transform.TransformDirection(new Vector3(50.0f, 0.0f, 0.0f));
			RBeam.velocity = transform.TransformDirection(new Vector3(50.0f, 0.0f, 0.0f));
		}
	}

Please, help me. I have the hope that Unity3D take me from my sad IT life and take me to the marvelous world of game development. :frowning:

Regards.

You forgot to include the velocity of the ship with your bullets. :slight_smile:

lBeam.velocity = rigidbody.velocity + transform.TransformDirection(new Vector3(50.0f, 0.0f, 0.0f));

Ok, i added that code but it doesn’t solve the problem. The projectiles keep going in angle like the second picture shows.

I guess that if there is no way to make the projectiles go straight while the ship is turning, i’ll have to remove the rigidbody of the projectiles and put a script in their prefab so it move forward ignoring the physics.

Laser Projectile.

uhh…

oxymoron - check; found your first problem :stuck_out_tongue:

If its supposed to be a beam the easiest thing to do would be to use a Raycast to a certain distance and apply a force to whatever it hits; could possibly use a Line Renderer component to make a laser effect.

I understand that there’s no thing as a laser projectile but i wanted to make something like in the Star Wars movies, they don’t shoot a straight beam, they go “pew pew”.

Anyway, i’ll just remove the rigidbody of the projectiles and put the moving script in them instead of the ship.