Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 spike2192 · May 13, 2012 at 05:49 PM · enemyfollowattackproximity

Enemy follows player then attacks!

Hi everyone. I am creating a zombie maze game. Pretty obvious what I've got to do. Got my character working tagged as "player", I've got box colliders on the bushes and i have an exit! I now am trying to add zombies to the game. I have no start script I am afraid. The zombies need to have 3 working animations "Zidle" and "Zwalk" then "Zattack". I need the zombies to see me and follow within a certain distance, whilst not walking through the walls. Then when they are close to the player, attack me! I will worry about health and that lot later!!! any help appreciated thank you!!!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · May 13, 2012 at 06:19 PM

First step, you need a destination. To detect the player, you can use Raycasts, trigger and overlapsphere. To pick a random pos for idle, you have Random.inUnitSphere.

The steering. Your zombi need to be able to go from point A to point B with the correct rotation. The simplest way is to use transform.Translate, or lerp and position.

If there is an obstacle, you can either make the zombi bump into it (they are stupid, after all) or find a path. If you have pro there you can use unity's path finding (but I can help) or you can try Aron's one or Angry Ant's one.

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
avatar image
0

Answer by spike2192 · May 13, 2012 at 07:52 PM

But i have no skills in javascript so i wouldn't even know where to begin with it all :/ thank you for your help, i will do some more searching

Comment
Add comment · Show 1 · 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
avatar image Berenger · May 13, 2012 at 08:29 PM 0
Share

If you are that new at coding, try something easier first. If you really want to stick with that project, here is a $$anonymous$$imal code :

var player : Transform; var speed : float = 5.0;

function Update() { transform.position = Vector3.Lerp( transform.position, player.position, Time.deltaTime * speed );

 var dist = (transform.position - player.position).sqr$$anonymous$$agnitude;
 if( dist < 1.0 ) // attack

}

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NPC code, works great, besides them being in the ground. 2 Answers

Enemies running when they should be following. 1 Answer

HitSpark for Enemy Collision 1 Answer

How to rig an enemy? 1 Answer

how to do to in second tap on screen of smartphone to create object and to this object look toward enemy but object look toward vector3 (0,0,0) 0 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