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
0
Question by Vadom6 · Jul 27, 2017 at 12:03 AM · player movement2.5dmeleeadvice

How would i go about implementing a melee system in a 2.5d game

So what i have in this 2.5d game is a simple movement and jump script and i would like to try and implement a melee script that can attack both left and right smoothly and make it so that it does damage but i don't know where to start.

This is my script:

 public Transform playertrn;
 public Rigidbody playerRB;
 public int speed;
 private bool isFalling = false;
 private bool doubleJump = false;
 public Vector3 JumpHeight = new Vector3 (0, 8, 0);


 void Start () 
 {
     playertrn = GetComponent<Transform> ();
     playerRB = GetComponent<Rigidbody> ();
     Physics.gravity = new Vector3(0, -11.0F, 0);
 }
 

 void Update () 
 {
     if (Input.GetKey (KeyCode.D)) 
     {    
         playertrn.Translate (new Vector3(speed, 0, 0) * speed * Time.deltaTime);
     }

     if (Input.GetKey (KeyCode.A)) 
     {
         playertrn.Translate (new Vector3 (-speed, 0, 0) * speed * Time.deltaTime);
     }

     if (Input.GetKey (KeyCode.Space) && !isFalling) 
     {
         playerRB.velocity = JumpHeight;
         isFalling = true;
     }

} void OnCollisionStay () { isFalling = false; } }

would i be able to get some advice on where to start with the melee system please

Thanks in advance

Comment
Add comment · Show 1
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 Cherno · Jul 30, 2017 at 02:42 PM 0
Share

I use a SphereCastAll to get all enemy colliders in the character's vincinity, then compare each enemy transform.position against the forward direction of the attacker so I only get those enemies in a narrow arc in front (for a slashing attack). If only exactly one enemy should be able to get hit, I just take the one with the smallest angle that is still withing the attacking angle threshold.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by CheetahSpeedLion · Jul 27, 2017 at 03:12 AM

The way I do my melee systems is by spawning a box collider, or box collider 2D in your case, where the attack is supposed to be happening. The enemy then has a hitbox that registers OnTriggerEnter() and lowers the enemy's health, knockback, etc. The "attack box", let's call it, can carry any info you'd like such as amount of damage and who sent the attack, which can then be transmitted to the enemy using OnTriggerEnter().

There are other ways to do it but this is my personal favorite. Another way is using raycasts I think.

Best of luck, Areleli Games

Comment
Add comment · Show 3 · 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 Vadom6 · Jul 30, 2017 at 03:31 AM 0
Share

Thank you so much i will look into this method the only issue i see is making it so that collider will spawn on either side depending on which way the player is facing

avatar image toddisarockstar Vadom6 · Jul 30, 2017 at 09:58 AM 0
Share

good answer by cheetah. another option would be to create a seperate collider or trigger on the edge of a sword. if you run into problems getting a seperate collision. just make a seperate rigidboby and collider on an unparented empty gameobject and update its location to the tip of the sword everyframe

avatar image Vadom6 toddisarockstar · Jul 30, 2017 at 10:49 PM 0
Share

Ok thank you that makes a lot more sense. you guys have helped me heaps thank you

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

71 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 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 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 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 avatar image avatar image avatar image

Related Questions

Weapon attack 0 Answers

Rotate scene or camera with unity 2d physics 0 Answers

How to achieve 2.5D movement along curve? 1 Answer

Best way to handle 2.5d punch attack? 1 Answer

How to create a path for the player in a terrain 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