|
I need an example of an enemy AI scipt, i can make a turret thanks to Tornado Twins and i assume i just put a transform position on it after the look at script to get it to follow but how would i do a senser for if my player is in the radius of like 40 then trigger it examples?
(comments are locked)
|
|
If I understand your question right, then you might be able to use this:
When you come close this "AI" it will look at you. If you get even closer it will follow you around until you run away from it. Just drag the target you want the AI to follow inside the slot in the Inspector named "target". Be aware that this is only a simple AI, you might need to change things inside the script or compine what TornadoTwins has thought you in order for this to suite your needs. Hope this has helped you. OL: Just thought you might be interested to know I plugged this script into one of my characters this morning after copying it out last night and it picked right up without error. Will take some tweeking, yes, but something simple was what I was looking for. Yours came up first and looks like the search ended. It'll save me days of original composition and frustration. Thank you.
May 31 '12 at 10:59 AM
BillEss
Just to add to that, later on I find myself wrestling with what looks like a common hurdle out there, detecting collisions by other objects with the player controller (when it's not moving.) For anyone else looking at OnPlayerColliderHit or raycasts or various other codey gymnastics to achieve that, the script in this answer may be a quick and efficient approach. Change distance to float and: if (distance < .3){ print ("Mom! " + transform.name + " is touching me!")
Jun 13 '12 at 12:52 PM
BillEss
THIS SCRIPT IS SO AWESOME!!!! THANK YOU!!!!!
Dec 31 '12 at 06:56 PM
Lost_C4
Thanks for this script. It has saved me a lot of time.
Feb 13 at 07:55 PM
Cornotiberious
I tried to use this script and what happened was my Enemy began spinning around my character at a high speed and i had no idea how to fix this
Apr 30 at 07:19 AM
fjcym11
(comments are locked)
|
|
use a sphere collider and check the isTrigger option. then make the collider as wide as you need it for your radius. then use the onTriggerEnter, onTriggerStay, and onTriggerExit for your on/off or whatever you need. http://unity3d.com/support/documentation/ScriptReference/Collider.html :-) when i try this script i get an error Assets/Scripts/Tank AI/Move to player.js(15,17): BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'.
Apr 03 '12 at 03:50 AM
Rhys_Pieces
(comments are locked)
|
|
did this get answered.. i get the same error Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float' Hi There. Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base. You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =] Under the answer where it says edit | delete | more , click on more , then convert to comment
Dec 13 '12 at 03:59 AM
alucardj
sorry bout that.. was in the wrong box..
Dec 13 '12 at 05:09 AM
trinitysj96
(comments are locked)
|
