- Home /
The question is answered, right answer was accepted
AI Instantiate targets/prefab. (pick target issue)
Ok so this time I have my AI instantiate an empty GameObject(prefab) at the hit point of one of the rays and then make that its target to follow/go towards.
The problem is that it doesn't select the prefabbed instantiated target but rather the original in he middle of the scene.
So yeah what do I need to do in order get it to pick the target which the AI insantiates.
Code:
 // This is whatever the AI targets.
 
 public Transform target;
 // This is the prefabbed target object that is instantiated.
 
 public Transform targetDummy;
 
 
 
 //and this where the magic is supposed to happen lol.
 
 if(Physics.Raycast(headdummyBone.position, fwd, out hit, maxDist, ignoreLayers)){
 
    if(startWandering == true && dummyTarget01Set == false){
 
       Instantiate(targetDummy, hit.point, transform.rotation);
 
 //this is where the target is set.
 target = targetDummy.transform;
 
 
 dummyTarget01Set = true;
 
 
 
 }
 
 
 
 
 
 }
Answer by HeliosDoubleSix · Aug 21, 2013 at 01:39 AM
Set it to the result of the Instantiate ( C# code ):
 GameObject resultingInstance = (GameObject)Instantiate(targetDummy, hit.point, transform.rotation);
 target = resultingInstance.transform;
Wait is that in Java?
Also it does not work.
no definition for transform and no extension method.
I tried adding a private Tranform instance but it didn't work.
Follow this Question
Related Questions
How to store player model and then swap the model to an object I Raycast hit? 0 Answers
C# GameObjects Instantiate Into Each Other Issue 1 Answer
Player instantiates Backwords 0 Answers
FPS Object-on-wall Placement 0 Answers
How to randomly spawn three non repeating gameobjects from an array? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                