Imaginalex avatar

Got a few attack animations working under unity.

imaginalex

Published: 27 Jun 2018 › Updated: 27 Jun 2018Got a few attack animations working under unity.

Got a few attack animations working under unity.

Thumbnail

I Successfully Implemented a few of my Attack Animations under Unity3D, they are my self made hammer attack animations and i added them to the character, each one of these attacks need to be held with the left hand, and the right hand respectfully, the basic attack is right handed and the uppercut / smash is partially left handed at the beginning and two handed at the end (it was painfull to code for a change / switch of hand between these two attacks but i found something that works pretty well)

That's how i came up with the solution to make bones attach to the other hand in c#, notice that i also had to change orientation / rotation and position of the hammer for each hand, but more specifically for the left hand, the hammer had to be tilted to another position.

void udate {
if (Input.GetKey(KeyCode.E))
{
//do the same but change parent on .SetParent
Fire2();

            if (Input.GetButtonDown("Fire2"))
            {
                animator.SetTrigger("attackTwo");
                hammer.transform.SetParent(hammer.transform.transform, false);
                hammer.transform.parent = lefthand.transform;
                hammer.transform.localPosition = new Vector3(-0.0177f, 0.0119f, -0.0287f);
                hammer.transform.localRotation = Quaternion.Euler(-161.379f, 15.812f, -36.125f);

            hammer.transform.localScale = Vector3.one;
        }
        }
 if (Input.GetKey(KeyCode.F))
    {
        Fire1();

        if (Input.GetButtonDown("Fire1"))
        {
            animator.SetTrigger("attackOne");

            //here you look for the same gameobject and parent it to the same gameobject, SetParent you put the object you want to parent the gameobject
            hammer.transform.SetParent(hammer.transform.transform, false);

            //this is used so it get the transform of the parent,it can be done in many other ways i did like this. Remove the .parent and put .position
            hammer.transform.parent = righthand.transform;
            hammer.transform.localPosition = new Vector3( -0.008f, 0.001f, 0.037f);
            hammer.transform.localRotation = Quaternion.identity;

            hammer.transform.localScale = Vector3.one;
        }
    }

And make public access variables to access the bones in the rig hierarchy of the character so the hammer would be able to be "summoned" from one hand to another :

Capture.JPG

My video is at DLive

Disabled and in bad health but still trying to at least do something of my day.

Leave Got a few attack animations working under unity. to:

Written by

I'm just a diversified artist that has a passion for game design and drawing. 💻indie game |🖱️💻 Digital Artist| Steemdya Game Dev

Read more #dlive posts


Best Posts From Imaginalex

We have not curated any of imaginalex's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Imaginalex