gameObject not destroyed after reaching desired coordinates.

#pragma strict

var speed : int = 10; 			//velocity of bullet
var upLimit : float = 5.0;


function Start () {

}

function Update () {
	
	transform.Translate(Vector3(0,0,speed*Time.deltaTime));
	Debug.Log(transform.position.z);
	if (transform.position.z >= upLimit){
		Destroy(gameObject);
		
	}
}

Hello guys. WhatI am trying to do is ro destroy my bullet after it reaches 5.0 or any desired coordinates in the grid. in the z axis. the code doesn’t seem to work. Is it a semantics error? Im a beginner coder obviously. some help is greatly appreaciated.

thanks :slight_smile:

The problem is that transform.translate moves the object on it’s own local axis, but transform.position is in world space.

You need to add Space.World to the translate line. See here:

However, this is only going to move your bullet in one direction. If you wanted to move the bullet in it’s own axis and limit the range, you’d need to store the starting position and measure the distance travelled instead.