Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
This question was closed Nov 20, 2016 at 09:24 PM by Midane53 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Midane53 · Nov 13, 2016 at 10:17 PM · c#rotationmovementgameobjecttransform

GameObject not looking at me..

Hi ! I got a problem. Surfed the web a lot to find a solution, But I don't know, i tried so much possibilities and variants, and it still doesn't work :( ! I'm trying to make a gameObject ( a creature ) rotating to look at me and then moving towards me. Here's my code, I really don't understand why the creature doesn't turn to me. Sorry for bag english grammar, I'm french c':

 using UnityEngine;
 using System.Collections;
 
 public class IA : MonoBehaviour {
 
     //Déclaration des variables
     bool joueurVu = false;
     public GameObject joueur;
     float mouvementSpeed = 2.5f;
 
     // Use this for initialization
     void Start () {
         joueur = GameObject.Find ("FPSController");
 
     }
     
     // Update is called once per frame
     void Update () {
         if (getDistance () < 10) {
             joueurVu = true;
             print ("Player seen!");
         }
 
         if (joueurVu) {
             transform.position = Vector3.MoveTowards (transform.position, joueur.transform.position, Time.deltaTime * mouvementSpeed);
             transform.LookAt (joueur.transform.position);
         }
     
     }
 
     //Autres méthodes
     float getDistance(){
         return Vector3.Distance (joueur.transform.position, transform.position);
     }
 
 }
 
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

1 Reply

  • Sort: 
avatar image
0

Answer by ElijahShadbolt · Nov 15, 2016 at 07:05 AM

That is a mystery. It works fine for me.

Maybe you put the script on the wrong object? It should be on the highest parent in the hierarchy of the creature.

I'm not sure about animations, but could they possibly be set to world space, to not update with rotation?

Also, on the 'if' statement on line 19, you might want to add an 'else' statement to set joueurVu to false.

 if (getDistance () < 10) {
     joueurVu = true;
     // ...
 } else {
     joueurVu = false;
 }
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 Midane53 · Nov 16, 2016 at 11:40 AM 0
Share

I will check that ! Jup adding an "else" sounds good ahah :P

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Auto level an object 0 Answers

My Prefab goes crazy and it moves faster when i click in another thing of the unity editor or the scene even if that didn't suppose to happen 0 Answers

How do you change your z axis in a movement script. 1 Answer

How To Make An Object Appear In Front Of Player Without Cloning? 1 Answer

Rotate GameObject with children around itself on mouse drag 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges