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 solly576 · Aug 31, 2013 at 11:35 AM · animationgun movement

Fix gun so it moves with the character correctly when changing animations

I have been working on animations for my player character in my zombie shooter game. When the player moves into the 'run' animation, the position of the hands change slightly, and then the gun is not aligned with the hands.

Here is a video: http://videobam.com/oGxoJ

Could anyone suggest a fix? The gun is a child of the player character.

Comment
Add comment
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

2 Replies

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

Answer by donnysobonny · Aug 31, 2013 at 12:28 PM

The simplest way to resolve a problem like this is to understand how child/parent relationships work with objects.

You may or may not have come accross the the localPosition/localRotation/localScale properties of the Transform class. When you make an object a child to another object, either by dragging it over the object in the heirarchy or by setting it's transform.parent to another transform (both methods do the same thing), the child object now uses the parent object as it's origin. Although it may not be entirely obvious at first, object which appear to have no parent do infact have the "World" as a parent.

So what does all of this mean?

Well, the easiest way to understand all of this is to create a cube, and then set it's position to 0,0,0. You will see that the cube is positioned to the center of the "World", this is because the cube's parent is the "World". Now, create another block, position is at 10,0,10, create a sphere and child the sphere with the block you just created. You can see that the sphere is a child of the cube by clicking on the little > to the left of the cube and there you will see the sphere. Now, set the sphere's position to 0,0,0. You will notice that the sphere is is in the center of the cube located at 10,0,10, therefore showing that child objects use the origin point of their parents as their own origin. Now if you move the cube currently located at 10,0,10, you will notice that the sphere remains it's localPosition to the cube, the same thing occurs when you change the rotation and scale. (the local position is the position using it's direct parent as the point of origin. The global position, or transform.position, is the position based on the "World" origin regardless of it's child/parent relationship.

So, to answer your question, you will need to locate the bone of the hand of your character, and then set the gun as a child to that bone. This will cause any movement/rotation/scale that happens to the hand to pass down into the position/rotation of the gun.

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 solly576 · Aug 31, 2013 at 01:17 PM 0
Share

Thanks, this really helped!

avatar image donnysobonny · Sep 01, 2013 at 02:30 AM 0
Share

No problem. I'm glad I could help.

avatar image
0

Answer by fherbst · Aug 31, 2013 at 12:14 PM

Make a script that syncs the positions of hand and gun in LateUpdate. You have to choose the direction (hand controls gun or gun controls hand), probably the gun should be the one updating the hand. (I wouldn't mess with the animation hierarchy)

Comment
Add comment · 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

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

18 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

Related Questions

Transition to sprint animation not working 0 Answers

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

Gun is not rotating while player is in a animation 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