raycast object instance offset?

Lads,

I’m using raycast and mousedown to swap one gameobject for another. All is working, but the instantiated object comes in offset (I’d like it to come in the exact position of the gameobject it’s replacing). I think the problem has to do with the hit.point of the ray or the destruction of the gameObject… not sure. Anyway, here’s the code:

function Update () {

	var hit : RaycastHit;
		if(Physics.Raycast (transform.position,
						transform.forward, hit, 500)) {
		if (hit.collider.gameObject.tag=="Block" 
		&& Input.GetMouseButtonDown(0) == true) {
    	var forward : Vector3 = transform.TransformDirection(Vector3.forward) * 500;
    	Debug.DrawRay (transform.position, forward, Color.green);
		
			//var instance2:GameObject = Instantiate (Resources.Load
			//("Detonator_explosion1"),transform.position, transform.rotation);
    		var instance:GameObject = Instantiate (Resources.Load
        	("building_stage_2_test"),hit.point, Quaternion.identity);
        	Destroy (hit.collider.gameObject);	
    
		}
   }
  }

Any thoughts?..

ps - the pivot locations of the object being instanced and the object being destroyed match.

Thx,

Stef

Well, you’re instancing it at the exact hit.point position. Use hit.transform.position instead, which is the pivot of the object that was hit.