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.