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 acmeydan · Jun 12, 2015 at 01:25 PM · enemy aiattackwaypointtower defense

enemy need to stop and shoot while walking on waypoint

I made a tower defence game, eveyrhting works perfect. The enemies are following waypoints, using hotween.

I want to make some enemies to attack towers, instead of just pass away. For this; i need a break while they follow waypoints, a code for detection of towers. I see that in the tower scripts, towers use bool void check range. How can i implement same system on enemies? This is the enemy waypoint script(not complete, but i guess this is the important part);

  IEnumerator OnSpawn()
     {
         //wait one frame so Start() gets called before OnSpawn() on a new instantiation
         //(we need to set "myID" before calling it below)
         yield return new WaitForEndOfFrame();
 
         //get Vector3 array with waypoint positions
         waypoints = pathContainer.waypoints;
 
         //get waypoint array of Vector3
         InitWaypoints();
 
         //start movement
         StartMove();
 }
 
 //initialize waypoint positions
     internal void InitWaypoints()
     {
         //recreate array used for waypoint positions
         wpPos = new Vector3[waypoints.Length];
         //fill array with original positions and add custom height
         for (int i = 0; i < wpPos.Length; i++)
         {
             wpPos[i] = waypoints[i].position + new Vector3(0, sizeToAdd, 0);
         }
     }
 
 
     //starts movement
     public void StartMove()
     {
         //we set this gameobject position directly to the first waypoint and
         //we also add a defined size to our object height,
         //so our gameobject could "stand" on top of the path.
         transform.position = wpPos[0];
         //we're now at the first waypoint position,
         //so directly call the next waypoint
         CreateTween();
     }
 
 
     //creates a new HOTween tween which moves us to the next waypoint
     //(defined by passed arguments)
     internal void CreateTween()
     {
         //prepare HOTween's parameters, you can look them up here
         //http://www.holoville.com/hotween/documentation.html
         ////////////////////////////////////////////////////////////
 
         //create new HOTween plugin for curved paths
         //pass in array of Vector3 waypoint positions, relative = true
         plugPath = new PlugVector3Path(wpPos, true, pathtype);
 
         //orients the tween target along the path
         //constrains this game object on one axis
         if (orientToPath)
             plugPath.OrientToPath();
 
         //create TweenParms for storing HOTween's parameters
         tParms = new TweenParms();
         //sets the path plugin as tween position property
         tParms.Prop("position", plugPath);
         tParms.AutoKill(true);
         //use speed based tween with linear easing
         tParms.SpeedBased();
         tParms.Ease(EaseType.Linear);
         tParms.OnComplete(OnPathComplete);
 
         //create a new tween, move this gameobject with given arguments
         tween = HOTween.To(transform, maxSpeed, tParms);
     }
 

Should i add public void? Or if state?

If they found a tower, they must stop and attack. There are many attacking script examples, this part is ok. But If tower hitpoint become zero/ they need to continue, but i dont how can i do this.

Thank you for your help.

Comment
Add comment · Show 1
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 Random10000000000000000000000 · Jul 24, 2015 at 09:41 PM 0
Share

I think you should look up ENU$$anonymous$$S, which hold different states of actions like say a patrol state or a EngageTarget state.

Also you should run a check like this to make sure you dont attack a dead tower: if(tower.health>0){ } This way you only attack a tower that isn't dead.

0 Replies

· Add your reply
  • Sort: 

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

22 People are following this question.

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

Related Questions

Get First Object In List 2 Answers

Enemy AI problems 2 Answers

rigidbody enemy goes only forward, no damage delay. 2 Answers

2D Enemy AI issues... 1 Answer

Enemy attack constantly with a coroutine 1 Answer


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