hey dudes!.. yo… i have a problem in doing a prefab follow a gameobject
well… what hapen is… this gameobject cannot be simple draged into a transform var, because i dont know exaclty what object the prefab shall pursuit, it can be a any object in the sceene , the one that is nearest to the prefab will be the one the prefab will chase…
but i dont need help exaclty in the part of discovering witch object is closer… i menage to do this already (with help of cool dudes from this forum) so my problem now is … how to make the prefab GO in direction of the target aquired…
heres my script so far
var mySphere : SphereCollider;
[COLOR="seagreen"]//this is a sphere collider without colision, i use this sphere to detect who's near[/COLOR]
var targets = gameObject;
[COLOR="seagreen"]// this var will transform in the closest gameObject that the sphere finds[/COLOR]
var misile : Transform;
[COLOR="seagreen"]// this is the projectile that i want it to chase the target found by the sphere[/COLOR]
private var wasTriggered : boolean;
function Start(){
mySphere = GetComponent(SphereCollider);
[COLOR="seagreen"]// start by casting a sphere that goes growing and growing until it touches any object with the tag "aimable"[/COLOR]
}
function Update(){
if(wasTriggered == false)
mySphere.radius += 0.5; //tweak to taste
}
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "aimable" wasTriggered == false){
mySphere.radius = 0;
targets = other.gameObject;
wasTriggered = true;
[COLOR="seagreen"] \\ it touched! ok now that it founded the gameobject, the "targets" var has that object attached to it.. so now i gotta launch the misile prefab (oh, i resized the sphere back to zero too)[/COLOR]
var LOOKHERE= targets.transform.position;
var sub = Instantiate (misile,GameObject.Find("SUBWEAPONPOINT").transform.position,Quaternion.identity);
misile.transform.LookAt (LOOKHERE) ;
sub.Rigidbody.AddForce (transform.forward * 900 )
[COLOR="seagreen"]\\this is the part that doesnt work.. i can cast the misile.. but he is not looking at the LOOKHERE direction.. and when i tell him to go forward.. he goes forward into my point of view, my plan was to make he go forward once he was looking at the target[/COLOR]
}
}