I tried to rotate it on the x then on the z but it’s always facing up.
The original position: The flashlight is facing back to the left.
When i check the checkbox in the Inspector on the Ik Active in the IK Control script i want the flashlight to rotate to the other side and to be facing to the right.
But this is what i’m getting when checking the checkbox on Ik Active: The flashlight is facing up:
The script:
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class IKControl : MonoBehaviour
{
protected Animator animator;
public bool ikActive = false;
public Transform rightHandObj = null;
public Transform lookObj = null;
void Start()
{
animator = GetComponent<Animator>();
}
//a callback for calculating IK
void OnAnimatorIK()
{
if (animator)
{
//if the IK is active, set the position and rotation directly to the goal.
if (ikActive)
{
// Set the look target position, if one has been assigned
if (lookObj != null)
{
animator.SetLookAtWeight(1);
animator.SetLookAtPosition(lookObj.position);
}
// Set the right hand target position and rotation, if one has been assigned
if (rightHandObj != null)
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position);
//animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
lookObj.rotation = Quaternion.Euler(180, 0, 180);
}
}
//if the IK is not active, set the position and rotation of the hand and head back to the original position
else
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 0);
animator.SetLookAtWeight(0);
}
}
}
}
I changed this line:
animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
With the line:
lookObj.rotation = Quaternion.Euler(180, 0, 180);
Since i want to rotate the flashlight when it’s active and to rotate the hand.
But i tried: 180,0 ,0 ,0 then 0, 0, 180 and now 180, 0, 180 but the flashlight is pointing up not to the right.
( And when it’s not active is it logic the flashlight to be facing to the left like in the original screenshot ? I mean like in idle when not using the flashlight or i should change the flashlight position/rotation to something more logic then facing left ? )