Object jumps in Y direction on mouse click

Hi all

I want to crate a missile that gets Instantiated from an object but which moves in the direction were the user has clicked on the screen, that is it should go from its originated position to the position were the user has clicked on the screen. sort of shooting an asteroid for a gun were the user take aim with the help of the mouse and the missile is fired.

I am using the following code to shoot the missile.

void BulletControle(){
Rigidbody Mybullet;
Ray mray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 distantPoint = mray.GetPoint (10);
Vector3 rDirection = mray.direction * 100;

if(Input.GetMouseButtonDown (0)){
Mybullet = (Rigidbody) Instantiate (bullet,this.transform.position,this.transform.rotation);
Mybullet.rigidbody.velocity =rDirection;
Destroy(Mybullet.gameObject,1.5f);
}
}

However when I use this with a moving object my object jumps in the “Y” direction as soon as i click the mouse button.

My object is a Rigidbody datatype. pls can any one explain me what i might be doing wrong.

NOTE: Iam new to unity programming.

Are you using a character controller with scripts to move the character?

No im not actually its a small airplane n Im using
“rigidbody.AddForce” property to move it forward to make it jump

“rigidbody.position” property to move it left or right

right now i have tried using a custom object actually it stopped jumping ! but still i want to if, if an rigidbody object is “Instantiate” another rigidbody does this problem occur ?

(I assume the bullet gets fired from the position of the camera? If not, you will also need to use a raycast to determine where it hits.)

The first thing to check with a misbehaving rigidbody bullet is whether it is colliding with the gun object itself. If so, you can fix it by using Physics.IgnoreCollision between the bullet and gun colliders.