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 ExyloN · Jul 18, 2012 at 06:33 PM · aienemypathfindingdetectionwaypoint

Enemy detection while pathfinding through the map

Hi guys, im creating a MOBA game like League of Legends. I'm almost done but there is one final thing to be made. I have enemies going from my base to the enemy base with multiple waypoints to get there. In what I need help, through the path that the enemies are running to get to the enemy base there are multiple turrets.

I want the enemies to:

  1. When a turret is near, they stop going to the next waypoint

  2. Move to the turret that is near them

  3. Stop at a certain distance of the turret

  4. Play an animation of attack (not necessary)

  5. When the turret dies the enemy goes to the next waypoint (The turret is already taking damage when the minion collides with the turret)

  6. Repeat this whenever a turret is near

I got to demonstrate the game tomorrow to my class and teachers, so any help is welcome.

Working Enemy Waypoint Script:

 var waypoint : Transform[];
 var speed : float = 20;
 var currentWaypoint : int;
            
 // Declaração de variáveis
 
 function Update()
 {
  if(currentWaypoint < waypoint.length)
  {
  var target : Vector3 = waypoint[currentWaypoint].position;
  // Saber onde está o caminho a percorrer
  var moveDirection : Vector3 = target - transform.position;
  var velocity  = rigidbody.velocity;
  
  // Rodar para o nosso caminho com determinada velocidade 
  
  if(moveDirection.magnitude < 1)
  // Saber o valor absoluto do número
  {
  currentWaypoint++;
  }
  else
  {
  velocity = moveDirection.normalized * speed;
  }
  }
  
  // Vai mover-se como na realidade e também poderá ser influenciado pela gravidade
  rigidbody.velocity = velocity;
  transform.LookAt(target);
 }

Script that im working with waypoints and enemy detection:

 var waypoint : Transform[];
 var speed : float = 20;
 var currentWaypoint : int;
 var Damage = 15;
 var maxDistance = 15;
            
 // Declaração de variáveis
 
 function Update()
 {
  if(currentWaypoint < waypoint.length)
  {
  var target : Vector3 = waypoint[currentWaypoint].position;
  // Saber onde está o caminho a percorrer
  var moveDirection : Vector3 = target - transform.position;
  var velocity  = rigidbody.velocity;
  
      var nearestDistanceSqr = Mathf.Infinity;
      var taggedGameObjects = GameObject.FindGameObjectsWithTag("MinionR"); 
      var nearestObj : Transform = null;
     
      // Loop that verifies who is the nearest enemy
      for (var obj : GameObject in taggedGameObjects) 
      {
          var objectPos = obj.transform.position;
          var distanceSqr = (objectPos - transform.position).sqrMagnitude;
      
          if (distanceSqr < nearestDistanceSqr) 
          {
              nearestObj = obj.transform;
              nearestDistanceSqr = distanceSqr;
          }
      }
      
  //Mecanismo de Disparo
  var distance = (nearestObj.transform.position - transform.position).magnitude;
  if(distance < maxDistance && Time.time > TimeToFireAt)
  {
  Fire(); //Criar disparo e efeitos
  TimeToFireAt = Time.time + FireRate; //Set Time
  }
  
  // Rodar para o nosso caminho com determinada velocidade 
  
  if(moveDirection.magnitude < 1)
  // Saber o valor absoluto do número
  {
  currentWaypoint++;
  }
  else
  {
  velocity = moveDirection.normalized * speed;
  }
  }
  
  // Vai mover-se como na realidade e também poderá ser influenciado pela gravidade
  rigidbody.velocity = velocity;
  transform.LookAt(target);
 }

Regards, ExyloN

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bovine · Jul 18, 2012 at 07:56 PM

Good luck, I'm afraid if you still have a lot of that list of things to do, you have a long, somewhat impossible night ahead.

What you're talking about is rudimentary AI. We have a tile based game and although simple, we ended up writing our own Behaviour Trees.

I would highly recommend this approach and it is possibly the quickest and cleanest approach there is, but you cannot write a BT in one night. You could, however, use the Behave library, but I don't know if the AngryAnt site is still running, so support may be tricky.

If you use the Behave library, I'd say there's a slim chance you could integrate and have it doing some or all of the above before morning.

Behave is a free behaviour tree library and can be found in the asset store.

Looks like Angry Ant is up and running still - it was not there the other day:

http://angryant.com/

There are some videos on Emil's site here:

http://angryant.com/wp-content/uploads/2010/09/Behave-starting-from-scratch.mov

http://angryant.com/wp-content/uploads/2010/10/FromTreeToCode.mov

AiGameDev provides some excellent resources for this kind of thing:

http://aigamedev.com/insider/article/behavior-trees/ http://aigamedev.com/premium/masterclass/unity-behave/

Not all of it is free I am afraid :(

it's a big topic, it might be too much to take in and integrate in one night, but it's probably the most robust and potentially the quickest and most flexible way to go.

Otherwise, it's time to hack!!

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 Bovine · Jul 18, 2012 at 07:58 PM 0
Share

If you're going with Behave, avoid decorators at all cost, they likely will NOT work the way that you think they do. I don't even think they work the way Emil says they do in the AiGameDev video!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

enemy waypoints and detection scipting 2 Answers

Enemy Not Facing target direction (waypoint) correctly when moving between waypoints 1 Answer

Waypoint System help 1 Answer

Obstacle avoidance not working 0 Answers

Enemy units behave normally, until they rotate, then their AI seems to break 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