• 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 TheEmeralDreamer · Sep 06, 2011 at 10:56 PM · quaternionparent

Weapon Parenting...v.2.0

I'll make this fairly simple. In code form, how would I go about creating an origin point for which an object would be parented.(I know about drag and drop, but i have multiple weapons.)

For instance if the right hand bone is the origin point, how would I go about placing a sword there. The code I have thus far parents the object, but it always appears at a strange angle because I added a child to the right hand and parented the weapon to the child. I'd like to do away with this and parent directly to the hand bone.

I've attached a picture here of what happens when I call this code.

http://i54.tinypic.com/2hptavd.png

Code--- function EqpWpn() {//set check so that more than one barrier can't be cast. var newEq=GameObject.Find("WeaponOrigin"); animation.CrossFadeQueued("Using Magic"); var clone; clone=Instantiate (weapon1,newEq.transform.position,Quaternion.identity); //send message, or add this to player obj code to update barrier hp. clone.transform.parent=newEq.transform;//make it parent. }

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

1 Reply

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

Answer by Tyler 10 · Sep 07, 2011 at 05:49 AM

After you parent the item, make sure to recenter it based on the parent.

clone.transform.localPosition = new Vector(0,0,0); clone.transform.localRotation = Quaternion.identity // or whatever rotation you want it to be relative to newEq;

Comment
Add comment · Show 6 · 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 TheEmeralDreamer · Sep 08, 2011 at 04:34 AM 0
Share

function EqpWpn() { var newEq=GameObject.Find("Bone_Hand_R"); var clone; clone=Instantiate (weapon1); //send message, or add this to player obj code to update barrier hp. clone.transform.parent=newEq.transform;//make it parent. clone.transform.localPosition =Vector3(0,0,0); clone.transform.localRotation.x=81.79031; clone.transform.localRotation.y=125.8506; clone.transform.localRotation.z=316.9125; }

avatar image TheEmeralDreamer · Sep 08, 2011 at 04:34 AM 0
Share

that is my current code. however it still is applied at a strange angle.

avatar image Tyler 10 · Sep 08, 2011 at 04:58 AM 0
Share

Sometimes its really hard to get your local position and rotation correct. So what I do is pause the game, and move the object to where its supposed to be and then copy the values out of the editor into my script. Are those the numbers from a paused state in the game?

avatar image TheEmeralDreamer · Sep 08, 2011 at 05:02 AM 0
Share

I honestly couldn't tell you but i do have some numbers i saved in a prnt screen. However when I place those numbers in, they do NOT align correctly.

avatar image TheEmeralDreamer · Sep 09, 2011 at 08:01 PM 0
Share

I'm still having major problems with this. Can anyone else offer insight? I've done everything this post says, but to no avail.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I parent an object to a bone? 2 Answers

force child rotation to zero? 2 Answers

Make a simple tree 1 Answer

Detecting the rotation of the current object? Shield resets when undertaking orbit. 2 Answers

Child versus Parent rotations 3 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