Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
public class SmoothFollowSchlau : MonoBehaviour
{
public Transform target;
public float DampPosition = 10.0f;
public float DampRotation = 10.0f;
public void Update()
{
if (!target)
return;
var currentRotationAngleX = Mathf.LerpAngle(transform.eulerAngles.x, target.eulerAngles.x, DampRotation * Time.deltaTime);
var currentRotationAngleY = Mathf.LerpAngle(transform.eulerAngles.y, target.eulerAngles.y, DampRotation * Time.deltaTime);
var currentRotationAngleZ = Mathf.LerpAngle(transform.eulerAngles.z, target.eulerAngles.z, DampRotation * Time.deltaTime);
var curposX = Mathf.Lerp(transform.position.x, target.position.x, DampPosition * Time.deltaTime);
var curposY = Mathf.Lerp(transform.position.y, target.position.y, DampPosition * Time.deltaTime);
var curposZ = Mathf.Lerp(transform.position.z, target.position.z, DampPosition * Time.deltaTime);
if (float.IsNaN(curposX) || float.IsNaN(curposY) || float.IsNaN(curposZ))
{
return;
}
// if (Lookat == false) {
this.transform.localEulerAngles = new Vector3(currentRotationAngleX, currentRotationAngleY, currentRotationAngleZ);
this.transform.position = new Vector3(curposX, curposY, curposZ);
// } else {
// this.transform.LookAt(GameObject.Find("TargetSmooth").transform);
// this.transform.localPosition = Vector3(curposX, curposY, curposZ);
// SmoothRotation(target.position, rotDamp); }
}
//function SmoothRotation( targetPos : Vector3, rotSpeed : float ) {
// targetRot = Quaternion.LookRotation( targetPos - transform.position );
// transform.rotation = Quaternion.Slerp( transform.rotation, targetRot, Time.deltaTime*rotSpeed ); }
}