Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to make the object face towards first person controller?

Discussion in 'Animation' started by Hachoumi, Mar 19, 2016.

  1. Hachoumi

    Hachoumi

    Joined:
    Nov 24, 2015
    Posts:
    18
    I want to make some sort of animation where when I approach a model object, it turns and faces me, how would I go on about doing that?
     
  2. 5vStudios

    5vStudios

    Joined:
    May 9, 2015
    Posts:
    106
    You can go about it couple ways:
    (1) - set a trigger that is triggered as the object is approached then start the animation sequence (Direction turn).
    (2) - set up a distance check, when the distance is less than a value of your choice (nearing object), start the animation sequence and have the object turn toward whatever.

    There are many ways you can go about it, those listed above are (in my opinion) the quickest and easiest options.
     
  3. Hachoumi

    Hachoumi

    Joined:
    Nov 24, 2015
    Posts:
    18
    I found a way to accomplish this by using a look rotation script, which basically transforms the object to face the assigned target.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RotatePos : MonoBehaviour {
    5.     public Transform target;
    6.     void Update() {
    7.         Vector3 relativePos = target.position - transform.position;
    8.         Quaternion rotation = Quaternion.LookRotation(relativePos);
    9.         transform.rotation = rotation;
    10.     }
    11. }
    12.  
    However, I am having a slight problem, when I approach this object, there seems to be some sort of collider which blocks my path to walk in. Is there any way to disable this?