Question by
Dog-Gamer · May 16, 2016 at 10:52 PM ·
javascriptprogramming
Wondering script Javascript
So i want to make a wondering script in javascript that if player is not hiding it follows you (Already programmed) but if you are hiding then it will wonder around toward or away from you. Any help? Here is my script which contains no wondering at all.
var target : Transform;
var moveSpeed = 3;
var rotationSpeed = 3;
var myTransform : Transform;
var variableObj: Transform; // drag the object with the hidden variable here
// get a reference to the target script (ScriptName is the name of your script):
var targetScript: NewHidingScript = variableObj.GetComponent(NewHidingScript);
// use the targetScript reference to access the variable Clips:
targetScript.hidden = false;
print("hidden="+targetScript.hidden);
function Awake(){
myTransform = transform;
}
function Start(){
target = GameObject.FindWithTag("Player").transform;
// get a reference to the target script (ScriptName is the name of your script):
var targetScript: NewHidingScript = variableObj.GetComponent(NewHidingScript);
// use the targetScript reference to access the variable Clips:
targetScript.hidden = false;
print("hidden="+targetScript.hidden);
}
function Update () {
// get a reference to the target script (ScriptName is the name of your script):
var targetScript: NewHidingScript = variableObj.GetComponent(NewHidingScript);
// use the targetScript reference to access the variable Clips:
print("hidden="+targetScript.hidden);
if (targetScript.hidden == false)
{
var dist = Vector3.Distance(target.position, myTransform.position);
var lookDir = target.position - myTransform.position;
lookDir.y = 0;
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
if(dist > 2.4){
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
else
{
//Random Wondering script here
}
}
Comment
Your answer
Follow this Question
Related Questions
Enemy keeps floating throw roof? 0 Answers
enemy looking randomly? 0 Answers
Spawn a dot for every number typed? 0 Answers
Have FPS Controller Crouch to hide player? 1 Answer
Why wont this work? 0 Answers