- Home /
Character always follow straight help!!!
Hi there so i have a character.. and i would like him to always to be drawn to the middle with his face forward.. like the one you see.. but when i get it to spawn.. it always follows with the wrong side.. and turns in the wrong way:
Here is the Code for the object if that helps:
using UnityEngine; using System.Collections;
public class EnemyScript : MonoBehaviour { public float moveSpeed = 3; public int health; private GameObject scoreObject; private Transform track; //private ScoreScript scoreScript;
void Awake ()
{
//scoreScript = GetComponent<ScoreScript>();
scoreObject = GameObject.Find ("Score");
}
void Start ()
{
track = GameObject.Find ("Center").transform;
}
void Update ()
{
float move = moveSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, track.position, move);
}
void OnMouseDown()
{
health = + -1;
if (health <=0)
{
scoreObject.GetComponent<ScoreScript>().AddScore();
Destroy(gameObject);
}
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Player")
{
Destroy(col.gameObject);
}
}
}
Well you are not showing the code for Instantiating the object and you don't seem to have any code in place to set the rotation either. You should just do something like
transform.eulerAngles = new Vector3(0, -135, 0);
// or
transform.LookAt(lowerLeftCornerPos);
Your answer
Follow this Question
Related Questions
Homing projectile 0 Answers
Camera rotation around player while following. 6 Answers
Main Camera child under player, causes flip 3 Answers
Camera follow - rotating rigidbody 1 Answer