• 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.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Enemy/Partner AI without rotation 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

Enemy AI C# 0 Answers

Enemy AI help 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges