I am trying to make a script in which the characters( goats ) jump from spot to spot.
I have an array of transforms which are jumpspots. The thing is that I only want them to jump to spots that are unoccupied so I am wondering how to do that. I have tried making another script for each transform with a boolean that indicates its state(full/empty).
I want to make ScanForTarget function to only look for targets that are empty. I imagine that I need to make a new array ( one that has only empty spots )from the possibleTargets array but am not sure how to proceed.I could not work out how to check the possibleTargets boolean states.
Also , how can I make to the (transform.LookAt(target) move through a smooth rotation?it is instantaneous at present.
Thanks.
var front_switch : boolean;
var customButton : GUIStyle;
var possibleTargets : Transform[];
var audioGoatObject : GameObject;
var other : Rigidbody;
var searchTag = "Respawn";
var smoothTime = 0.3;
private var velocity = Vector3.zero;
// the frequency with which to re-scane for new nearest target in seconds
// (set in inspector)
var scanFrequency = 1.0;
// the current target
var target : Transform;
function Update() {
// we rotate to look at the target every frame (if there is one)
if (front_switch==false){
transform.LookAt(target);
var targetPosition : Vector3 = target.TransformPoint(Vector3(0, 0,0));
other.useGravity = false;
// Smoothly move the camera towards that target position
transform.position = Vector3.SmoothDamp(transform.position, targetPosition,velocity, smoothTime);
}
}
function ScanForTarget() {
// this should be called less often, because it could be an expensive
// process if there are lots of objects to check against
target = possibleTargets[Random.Range(0, possibleTargets.length)].transform;
}
function OnGUI(){
if(GUI.Button(Rect(50,Screen.height -150,Screen.width/10,Screen.width/10),"",customButton))
{
ScanForTarget();
jump();
audiojump();
}
}
function jump(){
animation.Play("jump");
yield WaitForSeconds(1.5);
animation.CrossFadeQueued("loop_goat");
}
function audiojump(){
audioGoatObject.audio.enabled=true;
yield WaitForSeconds(1);
audioGoatObject.audio.enabled=false;
}