- Home /
some problems with my ai
I have some trouble with this:
var myDamage : int = 5; //or whatever var attackRange : float = 10; //whatever your sphereCollider's diameter is.
function Attack(target : GameObject) { if (Vector3.Distance(target.transform.position, transform.position) < attackRange) { Move(target.transform.position); } else { var targetHealth : Health = (Health)target.GetComponent("Health") as Health; //Casting in unity javascript. hideous. is why I use C# instead. targetHealth.Damage(damage); } }
function Move(targetLocation : Vector3) { //however your character moves. Physics? Simple Transform.Translate()? Too vague to suggest anything here. In any case, make it move towards targetLocation. }
function DoNothing() { //stop movement. make it scratch it's butt. }
"When comes in range it attacks": Have a gameObject called, say, AwarenessArea, childed to Zoombie. Give AwarenessArea a SphereCollider component. Make SphereCollider's diameter the same number you set attackRange to. make sure IsTrigger = true. Make a script called something like ZoombieAwareness (ZoombieAI?) and attach it to the AwarenessArea gameObject. Don't know how you've identified the player gameObject. Assuming you've given it a tag named "Player"
var myActions : ZoombieActions; function Awake() { myActions = (ZoombieActions)GetComponent("ZoombieActions") as ZoombieActions }
function OnTriggerEnter (thatThingIHit : Collider) { if ( thatThingIHit .CompareTag("Player")) myActions.Attack(thatThingIHit.gameObject); }
function OnTriggerExit (thatThingIHit : Collider) { if ( thatThingIHit .CompareTag("Player")) myActions.DoNothing(); }
Some trouble? This is mostly a pseudo-code: the function $$anonymous$$ove is empty, thus nobody will move. Where did you find this code?
my friend wrote it for my as an example but i confused and i cant find a ai script that doesn't walk thought walls
Answer by tyler.douglas · Dec 02, 2011 at 03:27 AM
my friend wrote it for me new to script so i very confused with ai scripts ive been looking for one that doesn't walk thought walls
Your answer
Follow this Question
Related Questions
Ai Zombie Melee Attack script. 5 Answers
Way Point Script Change Group 0 Answers
C# Script Not Working? (AdvancedAI) 0 Answers
Make the Enemy animation stops 0 Answers
How to get a Zombie to Chase Player at a certain distance? 3 Answers