Object spawning at 0,0,0

Hello. I am having a problem with a script. What this script does is instantiate a projectile at the player’s location and rotation. I cannot figure out why this is happening. Here is the script that instantiates the projectile. Any ideas? This script comes from the FPS tutorial.

var projectile : Rigidbody;
var initialSpeed = 20.0;
var reloadTime = 0.5;
var ammoCount = 20;
private var lastShot = -10.0;

function Fire () {
	// Did the time exceed the reload time?
	if (Time.time > reloadTime + lastShot  ammoCount > 0) {
		// create a new projectile, use the same position and rotation as the Launcher.
		var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
			
		// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
		instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

		// Ignore collisions between the missile and the character controller
		Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
		
		lastShot = Time.time;
		ammoCount--;
	}
}

If I got the question right, it happens because the transform is the object that shoots so to say, and you say explicitly “create projectile here with the same rotation and position as the transform has them”:

Instantiate (projectile, transform.position, transform.rotation);

P>S>, Sorry I am mean today: with 500+ posts here you should have known scripting better :stuck_out_tongue:

I am not a programmer.

Yes you are right. The transform is where the gun is. It worked fine, then just stopped randomly.

Is the script attached to the game object you think it is? :wink: Is that object at (0,0,0)…? Try modifying the script as follows:

var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
Debug.Log("instantiatedProjectile: "+instantiatedProjectile);
Debug.Log("our position: "+transform.position);
Debug.Log("its positon: "+instantiatedProjectile.position);
Debug.Log("its GO positon: "+instantiatedProjectile.transform.position);

What are the results?