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
1
Question by SirGive · May 11, 2011 at 11:52 PM · systemattack

Basic attack system

alt text So I'm currently working on a basic attack system and I wanted to know the best way to do this. I am currently relying heavily on the ThirdPersonCharacterAttack script converted to c#. I searched the wiki and couldn't find a single entry for an attack script. I figured that this might as well function for a good majority of new Unity users as well, so I'll work on this and update it here.

My basic issue:
I want to make an attack system in which I can attack 1 vs. 1 and 1 vs. Many. I attempted to illustrate this to get my idea across, and I hope it was helpful.

Now, I'm torn between:
using an actual circle and checking to see if enemies with the circle when the attack function is in progress

or
checking the distance between surrounding enemies and just seeing if they are close enough to be hit by my attack.

Which is more efficient?

Also, I was considering drawing a sphere and making it a trigger and thus checking the collision of objects with the tag "enemy" or some such thing.

Here is the code I'm currently working with:

void Start() { animation["punch"].speed = punchSpeed; punchPosition = new Vector3(0, 1.0f, 0); punchRadius = 0.1f; }

void Update () { ThirdPersonController controller = GetComponent<ThirdPersonController>(); if (!busy && Input.GetKeyDown(KeyCode.G) && controller.IsGroundedWithTimeout() && !controller.IsMoving()) {
SendMessage ("DidPunch"); busy = true; } }

 IEnumerator DidPunch ()

{ animation.CrossFadeQueued("punch", 0.1f, QueueMode.PlayNow); punchPosition.z = 1.0f; punchRadius = 1.0f; yield return new WaitForSeconds(punchHitTime); Vector3 pos = transform.TransformPoint(punchPosition); //var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("Enemy");

 //for (var go : GameObject in enemies)
 //{
     //var enemy = go.GetComponent(EnemyDamage);
     /*if (enemy == null)
         continue;*/

     /*if (Vector3.Distance(enemy.transform.position, pos) &lt; punchRadius)
     {
         enemy.SendMessage("ApplyDamage", punchHitPoints);
         // Play sound.
         if (punchSound)
             audio.PlayOneShot(punchSound);
     }*/
 //}
 yield return new WaitForSeconds(punchTime - punchHitTime);
 busy = false;
 punchPosition.z = 0.0f;
 punchRadius = 0.1f;

}

 void OnDrawGizmosSelected ()

{ Gizmos.color = Color.yellow; Gizmos.DrawWireSphere (transform.TransformPoint(punchPosition), punchRadius); }

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
1
Best Answer

Answer by Dreamer · May 12, 2011 at 01:49 AM

I think checking the distance is more efficient and easier to do. If you make a sphere trigger, each frame it will check the all 3D space to see if anything collides or not which is expensive. I am not sure about what's your thinking of doing it using circle. But I still believe checking distance is better, that's how I do for AOEs in my own RPG.

It would also be nice to mention that in a larger scale game, you could set up "territories" for areas that spawns of monsters roam in. This would stop all monsters from checking where you are.

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

No one has followed this question yet.

Related Questions

Attack Script 1 Answer

Attack system? 1 Answer

Hi what aproach would you condsider to make this kind of attack system,video included.J 0 Answers

Randomize health loss 1 Answer

Vehicle System Help 2 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