Got a few attack animations working under unity.

in #dlive6 years ago (edited)

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.

Sort:  

To listen to the audio version of this article click on the play image.

Brought to you by @tts. If you find it useful please consider upvoting this reply.

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.038
BTC 96483.87
ETH 3356.14
USDT 1.00
SBD 3.20