- Home /
Head Look for Mecanim
I have following script, how can i find position of mouse to look at? I wan't to make a script like Mouse Look in Standard Assets FPS, but for Mecanim.
using UnityEngine;
using System.Collections;
public class HeadLook : MonoBehaviour {
Animator animator;
void OnAnimatorIK (){
Vector3 target = ???
animator.SetLookAtPosition (target);
animator.SetLookAtWeight(1.0f);
}
void Start ()
{
animator=GetComponent<Animator>();
}
}
Answer by DynamicPrgm · Jan 23, 2014 at 05:42 PM
That depends on what you want to look at. If you want to look at an object, you could use
public Transform target;
And set in the inspector a target object. Then:
Vector3 target_look_position = target.position;
Or you could just hard code a vector3.
Vector3 target_look_position = Vector3(0, 0, 0);
no i'm trying to do different thing. i want to look using mouse. like it's on First Person Controller
So your game is in First person? If so then you could perhaps Raycast forward from the camera and take the hit position and use that as the position to set the rotation.
Vector3 target_look_position = hit.point;
Yes, but in first person, if the cursor isn't locked to the center, it could be off the screen. Do you mean rotate the head when the mouse is moved?
Your answer
Follow this Question
Related Questions
Animator.SetLookAtPosition is Inverted? 0 Answers
Animator not working with Legacy animations 2 Answers
Can Mecanim/Animator be used to make Enemy AI's? -1 Answers
Dynamic Mecanim animation speed/time 1 Answer