Mizzile [projectile] direction is wrong, please help

hello,

I am new to unity and learning the way game is made, pocess is long but i am here to stay

well, have a look here- Imgur: The magic of the Internet

i have attached a script to my missile, but projectile direction is wrong. I have barely started understanding c#

using UnityEngine;
using System.Collections;

public class firing : MonoBehaviour {
	
	//public GameObject particle;
	public Rigidbody projectile;
	public float speed = 50f;
	 
	
void Update() {
        if (Input.GetButtonDown("Fire1")) {
         Rigidbody clone;
			clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
			//clone.velocity = transform.TransformDirection(Vector3(0,0, speed));
			clone.velocity = transform.TransformDirection(Vector3.forward * 4);
			
            
        }
    }
}

any reply will be appreciated

try Physics.IgnoreCollision

Yeah,as sushanta says it could be that the projectile you’re spawning is instantly colliding with the gun and bouncing off in some direction. You can either prevent collisions between the two, or perhaps spawn your projectile a little forward from the gun so they never get the chance to collide in the first place.

Perhaps if you changed your instantiation line to something like:

clone = Instantiate(projectile, transform.position + transform.forward * 2.0f, transform.rotation) as Rigidbody;

it might do the trick.

In what axis is your projectile flying?
Or is it just flying with a wrong rotation?

If both are totally wrong, it may be crashing with some colliders.

You can try this

Create a child object for your weapon a few inches from the barrel, Instance your bullet on that point.

clone = Instantiate(projectile, foo.transform.position, foo.transform.rotation) as Rigidbody;

Where foo is your child object, also make sure your projectile instance is facing forward.

No need to use a fake pic to gain attention…

no need to dig up 10 month old threads…