Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 N3R0 · Mar 27, 2013 at 07:52 PM · animationeventfunctionsbind

Creating a function to use as an event in an animation?

Hello, i am relatively new to animating in unity and i am trying to create an animation where my characters picks up a sword and i am trying to create an event so when he grabs the sword, it binds to his hand so when i move his hand, the sword will move with it. how exactly would i go about doing this? sorry, i'm still learning

Comment
Add comment · Show 2
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 Unitraxx · Mar 27, 2013 at 08:06 PM 0
Share

Your question consists out of two parts. How to pick up a sword, and how to trigger the picking up during animation. Do you already know how to do one of these?

avatar image N3R0 · Mar 27, 2013 at 08:31 PM 0
Share

its the triggering the picking up i cant do, binding the sword two his hand in mid animation

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chronos-L · Mar 28, 2013 at 12:58 AM

You need to have these things:

  • A trigger that will detect the sword on the ground/closet

  • A bone/empty object parented to the palm, this will serve as the parent of the sword, you need to orientate this bone/object so that when the sword is held, the sword has the correct orientation

    Steps

  1. Detect for sword

  2. If pick-up key is pressed, and sword is detected, Go to step 3; else go back to Step 1

  3. Play pick-up animation; Time step 4 and 5 correctly using animation event

  4. Copy the orientation of the sword-parent to the sword itself

  5. Parent the sword to the sword-parent

    Example script

    public class PickUp : MonoBehaviour { public Transform swordParent; private Transform sword;

     void Update() {
           if( Input.GetKeyDown( KeyCode.C ) && sword != null ) {
              animation.Play("Pickup");
           }
        }
     
        void OnTriggerEnter( Collider other ) {
           if( other.gameObject.CompareTag("Sword") ) {
              sword = other.gameObject.Transform ; 
           }
        }
     
        void OnTriggerExit( Collider other ) {
           if( other.gameObject.Transform == sword ) {
              sword = null; 
           }
        }
     
        void PickUpSword() {
           sword.parent = swordParent;
     
           sword.localLocation = Vector3.zero;
           sword.localRotation = Quaternion.identity;
           sword.localScale = Vector3.one;
        }
     }
    
    

You will insert an animation-event in the Pickup animation clip to call the PickUpSword(). Please note that this is an example, you will have to do the integration yourself as I do not know how you structure/write your script.

You can even split the detecting function to another script, for example: SwordDetectArea.cs; so in your animation-controller script, you will do something like this:

 if( Input.GetKeyDown( KeyCode.C ) && swordDetectArea.sword != null ) {
    ...
 }
Comment
Add comment · Show 2 · 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 N3R0 · Mar 28, 2013 at 12:19 PM 0
Share

okay well, when i do this, there are a couple of issues that pop up when i do this, firstly when i parent the sword to the sword parent (the sword parent being his hand) the sword will follow his hand all through the animation when i just want it to follow his hand after hes grabbed the sword, is there a way to parent the sword to his hand in mid animation? also when i put the code in, it tells me "the type of namespace name "$$anonymous$$onoBehaviour" cannot be found" what does this mean? how can i fix this?

avatar image Chronos-L · Mar 29, 2013 at 12:37 AM 0
Share

Look at animation event, you can call the parenting-function in mid animation.

Start your .cs script like so:

 using UnityEngine;
 
 public class PickUp : $$anonymous$$onoBehaviour {
    ...
 }

The namespace $$anonymous$$onoBehaviour is defined in the UnityEngine. You should import it to be able to use it.

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

12 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

Related Questions

Multiple Cars not working 1 Answer

Animation Event don't show C# methods 1 Answer

Need help with some OnTrigger Scripting 2 Answers

Good design when starting animation and triggering event in animation? 2 Answers

Animation stoping!! 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