smooth unity code example
Example 1: unity smooth damp
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.3F;
private Vector3 velocity = Vector3.zero;
void Update()
{
Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
Example 2: smooth looking in unity
Transform target;
float turningRate = 2f;
turningRate /= 100;
Transform looker = null;
foreach(Transform child in transform)
{
if(child.name == "Child of Transform")
{
looker = child;
}
}
looker.LookAt(targetPlayer);
transform.localRotation = Quaternion.Slerp(transform.rotation, looker.rotation, turningRate * Time.deltaTime);