- Home /
Question by
GabrielBigardi · Jul 31, 2017 at 05:19 AM ·
c#scripting problemerror
Unity Follow backward
Hello, i'm trying to create a script (C#) where the transform follows a target, the current script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Follow : MonoBehaviour {
Transform target;
int moveSpeed = 3;
int rotationSpeed = 3;
Transform myTransform;
void Awake(){
myTransform = transform;
}
// Use this for initialization
void Start () {
target = GameObject.FindWithTag ("Player").transform;
}
// Update is called once per frame
void Update () {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
It works just fine for following, but it follow backwards, he is walking backwards to the character, i've tried to change the Y rotation already to 180, -180, but it still follow the character backwards.
Comment
Answer by MD_Reptile · Jul 31, 2017 at 05:21 AM
Is it possible the model is facing the wrong direction? You could put it under a empty gameobject in the hierarchy, and rotate it 180 degrees on Y, then instead of having this script move the actual object, move the empty object. If this works, than the Z forward isn't set right on that model.