I have my player so that when i right click a target my character moves towards it but my cahracter is not only moves towards the target it’s sinking father an farther into the plane. When i looked at my character closely it looks like my character is trying to meets it’s middle ( his chest with) with the targets middle ( the middle of the cube) if you need more detail on whats going on just ask. heres my script.
using UnityEngine;
using System.Collections;
public class Rotation : MonoBehaviour
{
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxDistance;
private Transform myTransform;
void Awake() {
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Enemy");
target = go.transform;
maxDistance = 2;
}
// Update is called once per frame
void Update () {
//Look at target
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, myTransform.position) > maxDistance) {
//Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
i have a separate script that activates this script, and im programming in C# and i am very new to programming so i wont know many advanced terms Thanks in advance!