• 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 wijesijp · Dec 05, 2013 at 07:28 AM · meleemelee attack

How to get 2 melee units to fight

I am designing tower defense game similar to kingdom rush. I have creeps that attack with a sword and hero attack with a hammer. Hero has an area to guard and he can’t move out of that area.

Both units have box colliders.

As you can see both these units have melee attacks. I am trying to design the logic for these units to fight with each other.

I am using A* path finding method to move units in the game. http://arongranberg.com/astar/

Scenario 1

Creeps see hero and move to hero’s last known position, hero sees creep he also move to creep’s last known position. If they collide they will fight. If they didn’t collide after reaching respective positions they will check others positions and try again. Please note that I am using A* path finding to move I can’t update the positions during the move. So they will move to last known positions.

Scenario 2

Creeps see hero and move to hero position, hero sees another creep and move to that creep position. When the first creep reaches hero’s last position he is no longer there …

As you can see there are quite a few situations like this. I am trying to design a system where these units behave properly. I guess we need some sort of a hand shake like system to avoid problems.

I am sure many of you have done systems like this and I was wondering whether some of you can share how you handle this situation.

I will be grateful if you can you post a method or pseudocode.

Comment
Add comment · Show 2
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 wijesijp · Dec 05, 2013 at 04:47 PM 0
Share

any suggestions on how to do something like this?

avatar image wijesijp · Dec 06, 2013 at 02:49 AM 0
Share

bump .......

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by amit-chai · Dec 05, 2013 at 09:16 AM

What is exactly the problem in Scenario 2? " When the first creep reaches hero’s last position he is no longer there …" wont he move the the next position? like in Scenario 1

Comment
Add comment · Show 4 · 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 wijesijp · Dec 05, 2013 at 09:50 AM 0
Share

yes

suppose the creep could learn the hero is moving to another position he could directly go there

my problem is the units are moving to positions to attack but the target unit has moved to somewhere else

avatar image wijesijp · Dec 05, 2013 at 09:56 AM 0
Share

I am planing to design system where units agree upon what to do, ins$$anonymous$$d of blindly going to places

like to get some idea how to do system like that from a someone who has done something similar ..

avatar image amit-chai · Dec 06, 2013 at 08:01 AM 0
Share

If you want your attackers to follow your hero, i would try to create a check for where is your hero, every X seconds. you can also create a 3rd point which is average of where your hero really is, and where it was X seconds ago.

avatar image wijesijp · Dec 06, 2013 at 11:36 AM 0
Share

good idea

but i am using A* path finding so updating positions is very costly operation.

Any other suggestions on how to do this?

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

hold key unequip sword 0 Answers

A Fighting Games Hit boxes 1 Answer

Detect whether the mouse has moved from left to right? 2 Answers

Hitting Multiple Enemies 1 Answer

Player Attack malfunction 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