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 Toto-_- · Mar 24, 2019 at 10:40 AM · scripting beginnerhitbox

I need help deciding the best way to pass different vector values to my hit-boxes and hit-forces depending on which attack is being used !! please help

I have an Attack Manager script that runs the characters animations for each attack, If possible I wanted to store the different vector values in my Attack Manager script and pass the values off to my individual hitboxes of which we have 10 (because of how the spine engine works with unity). Basically, I want the mutable variable/etc to be then used in the corresponding Hitbox script and the vector and force change depending on the animation/attack being used.

This is what I have set up so far in the Attack Manager... there are more attacks but all run on a similar base so didn't want to show too much code. * this is where I was thinking of setting up the vectors and forces. public class NinjaAttackManager : MonoBehaviour { SkeletonAnimation skeletonAnimation; [SerializeField] Rigidbody2D ninjaRigidbody;

     private float spAttCounter = 0f;
     [SerializeField] float specialAttackTime = 2f;
 
     private bool chargingStabCheck = false;
     private bool chargingStabUpCheck = false;
     private bool chargingStabDownCheck = false;
 
     private bool chargingSlashCheck = false;
     private bool chargingSlashUpCheck = false;
     private bool chargingSlashDownCheck = false;
 
     [SerializeField] KeyCode upControl;
     [SerializeField] KeyCode downControl;
     [SerializeField] KeyCode rightControl;
     [SerializeField] KeyCode leftControl;
     [SerializeField] KeyCode stabControl;
     [SerializeField] KeyCode slashControl;
 
     private Vector2 stabDirection0;
     private Vector2 stabDirection1;
     private Vector2 stabDirection2;
     private Vector2 backStabDirection0;
     private Vector2 backStabDirection1;
 
     private Vector2 slashDirection0;
     private Vector2 slashDirection1;
     private Vector2 slashDirection2;
     private Vector2 backSlashDirection0;
     private Vector2 backSlashDirection1;
 
 
     void Start()
     {
         skeletonAnimation = GetComponent<SkeletonAnimation>();
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         Slashes();
         SpecialSlashOver();
         SpecialSlashUp();
         SpecialSlashDown();
 
         Stabs();
         SpecialStabOver();
         SpecialStabUp();
         SpecialStabDown();
     }
 
     private void Slashes()
     {
         if (Input.GetKeyDown(slashControl))
         {
             if (Input.GetKeyDown(rightControl) || Input.GetKeyDown(leftControl) || Input.GetKeyDown(upControl) || Input.GetKeyDown(downControl))
             {
                 return;
             }
             else
             {
                 slashDirection0 = new Vector2(5f, 5f);
                 slashDirection1 = new Vector2(7f, 7f);
                 slashDirection2 = new Vector2(10f, 10f);
                 backSlashDirection0 = new Vector2(1f, 1f);
                 backSlashDirection1 = new Vector2(2f, 2f);
 
                 skeletonAnimation.state.SetAnimation(2, "Slash", false);
             }           
         }
         if (Input.GetKeyDown(slashControl) && Input.GetKey(upControl))
         {
             slashDirection0 = new Vector2(5f, 5f);
             slashDirection1 = new Vector2(7f, 7f);
             slashDirection2 = new Vector2(10f, 10f);
             backSlashDirection0 = new Vector2(1f, 1f);
             backSlashDirection1 = new Vector2(2f, 2f);
 
             skeletonAnimation.state.SetAnimation(2, "UpSlash", false);
         }
         if (Input.GetKeyDown(slashControl) && Input.GetAxis("Horizontal") > 0 || Input.GetKeyDown("x") && Input.GetAxis("Horizontal") < 0)
         {
             slashDirection0 = new Vector2(5f, 5f);
             slashDirection1 = new Vector2(7f, 7f);
             slashDirection2 = new Vector2(10f, 10f);
             backSlashDirection0 = new Vector2(1f, 1f);
             backSlashDirection1 = new Vector2(2f, 2f);
 
             skeletonAnimation.state.SetAnimation(2, "OverSlash", false);
         }
         if (Input.GetKeyDown(slashControl) && Input.GetKey(downControl))
         {
             slashDirection0 = new Vector2(5f, 5f);
             slashDirection1 = new Vector2(7f, 7f);
             slashDirection2 = new Vector2(10f, 10f);
             backSlashDirection0 = new Vector2(1f, 1f);
             backSlashDirection1 = new Vector2(2f, 2f);
 
             skeletonAnimation.state.SetAnimation(2, "DownSlash", false);
         }
     }

this is one of the Hitbox examples which all are basically identical just set that way for the individual trigger collisions for each collider. public class NinjaSlashHitbox0 : MonoBehaviour { //[SerializeField] Vector2 slashDirection; //[SerializeField] float slashForce = 50f;

     BoundingBoxFollower follower;
     [SerializeField] Transform myParentsObject;
 
 
     // Start is called before the first frame update
     void Start()
     {
         follower = GetComponent<BoundingBoxFollower>();
     }
 
     private void FixedUpdate()
     {
         //FlipForceDirection();
     }
 
     private void OnTriggerEnter2D(Collider2D otherObject)
     {
             if (otherObject.GetComponentInParent<Rigidbody2D>() == myParentsObject.GetComponentInParent<Rigidbody2D>())
             {
                 Debug.Log("I Hit Myself");
             }
             else if (otherObject.GetComponentInParent<Rigidbody2D>())
             {
             otherObject.GetComponentInParent<Rigidbody2D>().AddForce(slashDirection * slashForce);
             }
     }

Please, any advice tips or tricks would be very much appreciated! ps. I'm just self-taught over the last year on and off so if my code is garbage I apologize.. Also, I just noticed some small changes that I was making to it that I didn't update it all yet, incase you notice the inconsistency..

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 Toto-_- · Mar 23, 2019 at 04:47 PM 0
Share

Also, I should add that the Attack $$anonymous$$anager script is attached to the Parent game object then the hitboxes are all children to the game object with each hitbox having its own game object and corresponding script.

0 Replies

· Add your reply
  • Sort: 

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

106 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 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

Hello can anyone help me in my code i am converting some code JS to C# 1 Answer

How to Create Still Water Reflections [2D] C# 0 Answers

how can you make a 3D model slowly become transparent? 2 Answers

Make an object a certain distance from me. 2 Answers

loop vs if spell casting script 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