- Home /
Model is facing the wrong way
I made an AI script that makes objects randomly move about, but the model that I am using it on seems to be going backwards instead of forwards. I guess it thinks that it is going forwards because I did not tell it what direction it is supposed to face; how do I do so?
Have you made script for your AI if yes then upload it and its image also.
using UnityEngine;
public class AI : $$anonymous$$onoBehaviour {
public GameObject NPC;
public GameObject Cloned;
GameObject EyeClone;
private float Speed = -1;
private int Timer;
private int RandomSpeed = 1;
private float Rotation;
private int Growth;
public float Size;
private bool Growing;
private bool Adult;
private int Repoints;
private int Cap;
public int $$anonymous$$inCap;
public int $$anonymous$$axCap;
public int TreeLimit;
void Start (){
Random.InitState (67);
Growing = true;
Adult = false;
TreeLimit = 5;
Cap = Random.Range ($$anonymous$$inCap, $$anonymous$$axCap);
NPC.transform.localScale = new Vector3 (0.5f * Size, 0.5f * Size, 0.5f * Size);
}
void Update () {
if (Growing == true) {
Growth += 1;
NPC.transform.localScale += new Vector3 (0.0005f * Size, 0.0005f * Size, 0.0005f * Size);
}
Rotation = NPC.transform.eulerAngles.x;
if (Speed == 0) {
NPC.transform.Rotate (Vector3.up * 150 * Time.deltaTime);
}
NPC.transform.Translate (Vector3.forward * Speed * Time.deltaTime);
NPC.transform.Translate (Vector3.right * Speed * Time.deltaTime);
Timer += 1;
if (Timer >= 50) {
Timer = 0;
Speed += Random.Range (-1, 1);
}
if (Speed >= 6 | Speed <= -6) {
Speed = 0;
}
if (transform.position.y < 0) {
NPC.transform.Translate (Vector3.up * -NPC.transform.position.y);
}
if (Rotation >= 80) {
NPC.transform.Rotate (Vector3.left * Rotation);
}
if (Growth >= 1000.0){
Growth = 0;
Adult = true;
Growing = false;
NPC.transform.localScale = new Vector3 (1f * Size, 1f * Size, 1f * Size);
}
if (Adult == true) {
Repoints += 1;
if (Repoints >= Cap & TreeLimit > 0){
EyeClone = Instantiate (Cloned, transform.position, Quaternion.identity) as GameObject;
Cap = Random.Range ($$anonymous$$inCap, $$anonymous$$axCap);
Repoints = 0;
TreeLimit += -1;
}
}
}
}
Answer by godberzerker · Oct 02, 2017 at 06:32 AM
hey, not to worry actually the thing u r facing is very common it maybe becoz of ur 3d model software or the model u downloaded the thing is tht ur model has its axis in different direction according to unity to make things workout create an empty gameobject and position it in the centre of ur model and parent the model to the empty gameobject and add the script to the empty game object i also faced this problem if u hav more questions ( beginner level questions) plz ask if the answer is not clear then let me know
Your answer
Follow this Question
Related Questions
3th Person Character Facing wrong direction 1 Answer
Getting the face direction 2 Answers
How do i make a "summon" object - and let the player face in its direction? 0 Answers
Raycast in the wrong way 3 Answers
Help with my "CanHitTarget" function 2 Answers