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 Kergal · Mar 23, 2012 at 09:58 AM · c#aienemywaypoint

Send an enemy back to its spawn point using waypoints

Hi, so far my enemy is walking towards the player when the player is in a certain range of the enemy. When the enemy reaches meleeAttackrange it attacks and when the player manages to get out of the enemies deception radius - the enemy runs back to its spawn point. Here is where I have a problem. So far the enemy chooses the shortest way back to its spawn, which is quiet a problem since my level is a dungeon. The enemy runs against the closest wall .... My idea was to send the enemy back to its spawnpoint using waypoints. I have placed some lights in my map on strategic points and attached an empty gameobject (waypoints) to those points. The plan is to make the enemy search for the closest waypoint and walk to that waypoint and then decide wether it needs another waypoint to reach the spawnpoint or wether it can reach the spawnpoint without walking to another waypoint.

I am still thinking about this problem . So far I have the following idea:

create a function called findwaypoint.

in this function i am checking the distance of the enemy.position to the waypoint position closest to the enemy. If walking to this waypoint shortens the distance between the enemy and the spawnpoint - walk() is called and then check again until the enemy reaches the spawn point.

There is a flaw in my logic. and i still cant figure out how to manage... the shortest distance from the enemy to the spawn is the straight line and walking to the right waypoint might enlengthen this distance. Further, right now this idea may choose a waypoint that leads to nowhere...

unfortunately i am not sure how to make a walk home using waypoint function. Does someone have an idea?

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 Statement · Mar 23, 2012 at 03:31 PM

Consider using the path finding system in Unity 3.5 (Requires Unity Pro) or other third party path finders.

If you want to roll your own code, maybe you should start with an A* solver. Also, I would treat a no line of sight to target as a bad path and ignore that all together, so you might want to ignore all possibilities that clearly lead nowhere.

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 Kergal · Mar 26, 2012 at 06:36 PM

Hi, thank you for your answer. It might take some time until I will be able to fully understand path finding systems the way I need them to work :)

I admit, I am new to unity and at the moment I simply cannot afford the pro version and I don't want to download the pro version illegally. However, it is on my wishlist :D

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Why doesn't this AI script work? c# 1 Answer

Waypoint System help 1 Answer

2D AI, Aim at player - even when jumping? 1 Answer

AI script works, when we add a blocked function it stops working HELP 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