• Unity
  • Services
  • Made with Unity
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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 /
  • Help Room /
avatar image
0
Question by wnsgk4862 · Aug 17, 2018 at 08:38 AM · unity5inverse kinematic

LeftHand IK Target in weapon that is child of righthand?

I wanted to attach lefthand to my weapon, so i tried to use IK system. I made weapon be a child of righthand. and add leftHand IK Target to weapon. problem is, when the leftHand IK Target is not below rightSoulder, it works well. but when it is below rightShoulder, it works so weird. Why does this thing happen? and how to solve this problem?

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(AimSystem))]
 public class AimIK : MonoBehaviour {
 
     //Other component
     private Animator m_Ani;
     private AimSystem m_Aimsystem;
 
     private Transform m_AimTarget;
     public Transform m_AimPivot;       //This will make hands up and down according to direction player is looking.
     private Transform m_RightShoulder;
 
     //Grab Points
     public Transform m_LeftHandPosition;
     public Transform m_RightHandPosition;
     public float m_LeftHandIKWeight = 1f;
     public float m_RightHandIKWeight = 1f;
 
     public float m_LookWeight = 1;
     public float m_BodyWeight = 0.9f;
     public float m_HeadWeight = 1;
     public float m_EyesWeight = 1;
     public float m_ClampWeight = 1;
 
     // Use this for initialization
     void Awake () {
         m_Ani = GetComponent<Animator>();
         m_Aimsystem = GetComponent<AimSystem>();
         m_AimTarget = m_Aimsystem.m_RayTarget;
         m_RightShoulder = m_Ani.GetBoneTransform(HumanBodyBones.RightShoulder).transform;
     }
 
     private void OnAnimatorMove()
     {
         SetAimpivotPosition();
         SetAimpivotRotation();
     }
 
     private void OnAnimatorIK(int layerIndex)
     {
         //Hand IK
         if(m_LeftHandPosition)
         {
             m_Ani.SetIKPositionWeight(AvatarIKGoal.LeftHand, m_LeftHandIKWeight);
             m_Ani.SetIKPosition(AvatarIKGoal.LeftHand, m_LeftHandPosition.position);
             //m_Ani.SetIKRotationWeight(AvatarIKGoal.LeftHand, m_LeftHandIKWeight);
             //m_Ani.SetIKRotation(AvatarIKGoal.LeftHand, m_LeftHandPosition.rotation);
         }
 
         if (m_RightHandPosition)
         {
             m_Ani.SetIKPositionWeight(AvatarIKGoal.RightHand, m_RightHandIKWeight);
             m_Ani.SetIKPosition(AvatarIKGoal.RightHand, m_RightHandPosition.position);
             m_Ani.SetIKRotationWeight(AvatarIKGoal.RightHand, m_RightHandIKWeight);
             m_Ani.SetIKRotation(AvatarIKGoal.RightHand, m_RightHandPosition.rotation);
         }
 
         //Look IK
         m_Ani.SetLookAtPosition(m_AimTarget.position);
         m_Ani.SetLookAtWeight(m_LookWeight, m_BodyWeight, m_HeadWeight, m_EyesWeight ,m_ClampWeight);
     }
 
     public void SetHandsIKPosition(Transform _righthand, Transform _lefthand)
     {
         m_LeftHandPosition = _lefthand;
         m_RightHandPosition = _righthand;
     }
 
     public void SetAimpivotPosition()
     {
         m_AimPivot.position = m_RightShoulder.position;
     }
 
     public void SetAimpivotRotation()
     {
         //Weapon Direction IK
         Vector3 DestDir = m_AimTarget.position - m_AimPivot.position;
         Quaternion TargetRotation = Quaternion.LookRotation(DestDir);
 
         m_AimPivot.rotation = Quaternion.Lerp(m_AimPivot.rotation, TargetRotation, Time.deltaTime * 20);
     }
 }
 

ik-problem-in-game.png (216.2 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Doomed animation (Inverse kinematics) 0 Answers

Unity 5 Custom Imported Trees 1 Answer

Multitouch Windows 7 disable cursor 0 Answers

the best overload method ...cant seem to get work!! 1 Answer

Continuous rotation on key press? 2 Answers

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