• 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 awplays49 · Jan 18, 2015 at 02:24 AM · childchildrenweaponweaponsarms

methods of positioning weapons to hand

what do you do for this step by step so its always going through the players hand, even when the arm moves?

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
0
Best Answer

Answer by carrollh · Jan 18, 2015 at 02:46 AM

EDIT: after seeing @michael96schmidt's answer, it made me realize why I do it this way in my game. My weapons have rigidbodies and a lot of mass so they can bash things around. The more mass the thing has the further out of position it will get as you move around. His method is way better if you don't need rigidbodies on the weapons. You can achieve it in code with something like weapon.transform.SetParent(attachPoint.transform) /EDIT

The way I do it (which may be the naive way or the preferred way, I don't know), is in 2 parts:

1) After adding the character model to the scene, in the hierarchy I expand the joint tree for the character until I find where I want to put dynamic stuff (holsters, hands, etc). Then I add GameObjects to these joints, and then translate and rotate them into the correct position for what I need.

2) Then I attach a script to the weapon or object that looks like this:

 using UnityEngine;
 
 public class Weapon : MonoBehaviour {
 
     public Transform attachPoint;
     public GameObject owner;
     
     void Start()
     {
         if (owner != null)
         {
             transform.localScale = owner.transform.localScale;
         }
     }
 
     void Update()
     {
         if (owner != null)
         {
             transform.position = attachPoint.position;
             transform.rotation = attachPoint.rotation;
         }
         else Destroy(gameObject);
     }

3) Then I drag the GameObject I added to act as an attachment point or holster onto the scripts public Transform attachPoint in the Inspector.

Note: You might not need the Start() method or the Destroy call. For example you want the sword or whatever to stick around in scene after the owner dies or whatever.

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
avatar image
2

Answer by michael96schmidt · Jan 18, 2015 at 05:54 AM

I just put an empty gameobject as a child of the hand/arm and offset it to be in the position of where the weapon would be. I then just have the equipped weapon a child of that gameobject.

Comment
Add comment · Show 1 · 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 carrollh · Jan 18, 2015 at 05:00 PM 0
Share

This should totally work, as long as you don't have a rigidbody with any mass attached to the weapon. If you do, you'll have to update the weapon's position and rotation to stay put periodically.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Loop to find a child in every children's child? 1 Answer

Create Clones as children in loops? 1 Answer

(C#) How do I run something in my child's script? 2 Answers

Animations for different weapon styles 0 Answers

Switch for children not working 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges