Hello,
so i got a Script that Follows my Spaceship around, Everything works fine, but if i rotate around the z axis my camera also rotates z and x, but why x, maybe you guys can help me with that.
thank you Maxi
this is the normal state,
and this if i roll,
public Transform target;
public Vector3 defaultDistance = new Vector3(0f,2f,-10f);
public float distanceDamp = 10f;
public float rotationDamp = 2f;
public Vector3 velocity;
bool foundTarget;
private void Start()
{
foundTarget = false;
}
// Use this for initialization
void Update () {
if (!foundTarget)
{
target = GameObject.FindGameObjectWithTag("Ship").transform;
foundTarget = true;
}
}
// Update is called once per frame
void LateUpdate () {
SmoothFollow();
}
void SmoothFollow()
{
Vector3 toPosition = target.position + (target.rotation * defaultDistance);
Vector3 curPosition = Vector3.SmoothDamp(transform.position, toPosition,ref velocity, distanceDamp);
transform.position = curPosition;
transform.LookAt(target, target.up);
}
void SmoothFollowLerp()
{
Vector3 toPosition = target.position + (target.rotation * defaultDistance);
Vector3 curPosition = Vector3.Lerp(transform.position, toPosition, distanceDamp * Time.deltaTime);
transform.position = curPosition;
Quaternion toRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
Quaternion curRotation = Quaternion.Slerp(transform.rotation, toRotation, rotationDamp * Time.deltaTime);
transform.rotation = curRotation;
}
}