Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 nhftk12 · May 29, 2011 at 03:07 PM · meleesword

Pull out the sword and attack the enemy that close to me and in front of me

I want to add some melee attacking to my game. I know how to use melee attack but when I know who is the enemy and I don't in front of him.

First thing in melee attacks I need to pull out my sword so I'll be able to attack. I made an animation for that (grab the sword and pull) but I don't know how to pull the sword out. If I don't wrong you need attach the sword to the bone in the hand while the animation is play (correct me if I'm wrong). How I can pull in and out the sword? (The sword is not attach to anything, don't have rigidbody and I don't have any code for that).

After I pull my sword out I need to attack. The melee attacks I did before was that only the enemy able to do melee attack (works perfect) but now I want me to do that.

This is the part of the enemy's melee code:

 function Attack ()
  {
      if (canAttack)
      {
          if (ableMove)
          {
              animation.Play("Stop");
              yield WaitForSeconds (0.3);
              attackTest = true;
              ableMove = false;
          }
          
          if (attackTest)
          {
              animation.Play("Hit");
              CharacterControl.healthBarDisplay -= 0.1;
              canAttack = false;
              yield WaitForSeconds (coolDown);
              canAttack = true;
          }
      }
  }

(That code works fine) If I attach that code to my character it will work also but not when I fase to the enemy and when I fight against enemy that not defined as my target. (It works with the enemy because he always look at me and I am he's only target...). How I can do melee attacks when I fase an enemy? (I don't care how much enemys, if there is an enemy in front of me and close to me - he loss health). If I don't wrong you need to use tags (correct me again if it wrong).

Sorry for poor english.

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 eaves · May 29, 2011 at 04:50 PM

From what I understand, All you need is more animations:

1- Animation for the player standing still

2- Animation for the player pulling the sword

3- Animation for the player standing still WITH the sword

4- Animation for the player attacking with the sword

so when you want to pull the sword out you play the "PULL SWORD" animation and then change the default animation cycle to "STANDING STILL WITH SWORD" then whenever you hit you play the "ATTACK WITH SWORD" animation

as for knowing when the enemy is near you, there is a standard used in many games called "Hit Box" , that's a collider (make it a trigger) attached to the enemy gameobject.

and when your player's collider enters(or stays inside) the enemy's collider , you call

 var currentEnemy : GameObject;
 function OnTriggerEnter(other : collider){
 
 
 currentEnemy = other.gameObject;
 
 }


and use "currentEnemy" in your code to recieve hits, play "GETTING HIT" animation, and so on

also dont forget to set the "currentEnemy" to null if your player is outside the hitbox of the enemy so that you cant attack the enemy from far away.

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 nhftk12 · May 30, 2011 at 04:11 AM 0
Share

I don't undersand it so much... Both pull the sword and the attacks...

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

2 People are following this question.

avatar image avatar image

Related Questions

RPG Swing attack hit detection 6 Answers

on collision damage 1 Answer

What is the best way to do third person melee combat? 1 Answer

First person sword fighting 1 Answer

Sword Combat System: Detect if player in range 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