Hello i am new to Unity and am making a Hunting game and wan’t the animals i don’t have any yet and would appreciate it if some one could direct me to a Free model any way i wan’t the animal to walk around randomly and i got a script [hear][1] that won’t work if i put the script on me character. I do know a little about code and have hunch that it has something to do with the called animations. Any way hera is the script.
PUBLIC VARIABLES
Points - array of waypoint gameobjects
Start Point Index - The point in the array character should start at
Move Speed - um, the move speed
Attack speed multiplier - the move speed will be multiplied by this when attacking
Player - if the character can attack you, set this to the player game object
Attack Range - how close you can get to the character before it will attack you
Hit Range - how close the character needs to get to you before it will stop chasing and start smacking
Search time - if you trying to hide behind something while being attacked, attacker will continue search for you for this long (in seconds)
Min Wait Time - when getting a new way point target, what is the minimum about of time to wait before proceeding
Max Wait Time - when getting a new way point target, what is the maximum about of time to wait before proceeding
Constantly randomise points - if true, then the array of points will be shuffled before the next waypoint is selected
If you are not presetting any points and want the script to randomly generate points, set the following
Point Marker - the GameObject to instantiate for each point
Random Range - how far away from the characters starting position can the random points be generated
Random Points to create - the number of random points to generate
Random Points above char - the starting y position (above the character) for the random points before they drop to the ground. In hilly areas this should be quite high, in flat areas it can be low
*/
var points: GameObject[]; var startPointIndex:int = 0; private var targetPoint:int = startPointIndex; var moveSpeed: float = .05; var attackSpeedMultiplier:float=100.0; var player:GameObject; var attackRange:float=25.0; var hitRange:float=5.0; var searchTime:float=5.0; private var targetPosition: Vector3; private var changeDistance:float; private var yPos: float; private var paused: boolean=true; var minWaitTime: float=1.0; var maxWaitTime: float=5.0; var constantlyRandomisePoints: boolean=false;
var pointMarker:GameObject; var randomRange:int =20; var randomPointsToCreate:int=6; //this variable is used to control how high above the character random points should be created. They will then drop down until they hit the ground.
var randomPointsAboveChar:int=5; private var targetPositionForRotation:Vector3; private var controller : CharacterController; //init char after all points have landed
private var initialised:boolean=false;
private var tempPoints:Array=new Array(); private var tempPointCounter:int=0; private var tempPointPosition:Vector3; private var minPointSpace:float=1;
private var attackingPlayer:boolean=false; //the time that the attacker lost sight of the player private var lostTime:float; private var currentTargetObject:GameObject;
function init(){ initialised=true; transform.position.x=points[targetPoint].transform.Find("Registration").transform.position.x; transform.position.z=points[targetPoint].transform.Find("Registration").transform.position.z; transform.position.y=points[targetPoint].transform.Find("Registration").transform.position.y; //this was just for testing //GameObject.Find("First Person Controller").transform.position=points[targetPoint].transform.position+Vector3(-3,2,-3); //GameObject.Find("First Person Controller").transform.rotation=Quaternion.identity; transform.Find("EmitFlames").GetComponent(ParticleEmitter).emit=true; getNewTarget(0); ignoreCollision("Point");
}
function Start(){ if(points.length==0){ //no points assign - create random points around character points=new Array(randomPointsToCreate); for(i=0;ihitRange){ animation.CrossFade("run"); controller.SimpleMove(moveSpeedattackSpeedMultipliertransform.TransformDirection(Vector3.forward)); }else{ animation.CrossFade("jump"); } } //don't rotate at the very start if(targetPositionForRotation!=Vector3.zero && targetPositionForRotation!=null){ if((targetPositionForRotation - transform.position)!=Vector3.zero){ var rotation = Quaternion.LookRotation(targetPositionForRotation - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 3); } } //Debug.Log(Vector3.Distance(transform.position, player.transform.position)); if(player!=null && Vector3.Distance(transform.position, player.transform.position)searchTime){ if(attackingPlayer){ paused=true; animation.CrossFade("idle"); getNewTarget(Random.Range(minWaitTime,maxWaitTime)); } attackingPlayer=false; } } }else{ //before we set attackingPlayer to false, check if we were just attacking character and if so get a new target if(attackingPlayer){ paused=true; animation.CrossFade("idle"); getNewTarget(Random.Range(minWaitTime,maxWaitTime)); } attackingPlayer=false; } }
function CanSeePoint (t:GameObject) : boolean { var startPos:Vector3=transform.position; startPos.y+=controller.height/2; var hit : RaycastHit; if(t!=null){ if (Physics.Linecast (startPos, t.transform.position, hit)){ //Debug.Log(hit.collider.gameObject.name); return hit.collider.gameObject == currentTargetObject; } } return false; }
function CanSeePlayer (t:GameObject) : boolean { var startPos:Vector3=transform.position; startPos.y+=1; var hit : RaycastHit; //when looking for character, ignore hits with point objects // Bit shift the index of the layer (8) to get a bit mask var layerMask = 1 << 8; // This would cast rays only against colliders in layer 8. // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask. layerMask = ~layerMask; if (Physics.Linecast (startPos, t.transform.position, hit,layerMask)){ //Debug.Log(hit.collider.gameObject.name); return hit.collider.gameObject == player; } return false; }
function Shuffle(a:Array){ var temp:GameObject; for(i=0;i