• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tyler.douglas · Dec 02, 2011 at 12:34 AM · aizombie

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(); }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aldonaletto · Dec 02, 2011 at 01:00 AM 0
Share

Some trouble? This is mostly a pseudo-code: the function $$anonymous$$ove is empty, thus nobody will move. Where did you find this code?

avatar image tyler.douglas · Dec 02, 2011 at 02:55 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

My zombie rotates sideways when it walks towards me or when I walk to him 0 Answers

My Zombie Model is coming at me sideways with the AI 1 Answer

looking to make for a zombie script AI,navmesh or not? 2 Answers

Zombie AI tutorial 2 Answers

Zombie A.I path finding help 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges