自定义的插值公式
程序员文章站
2022-07-08 08:23:00
自定义的插值公式1using System.Collections;using System.Collections.Generic;using UnityEngine;namespace ACTBook{ /** * static function Repeat (t : float, length : float) : float * 循环数值t,0到length之间。t值永远不会大于length的值,也永远不会小于0。 * 这是类似于 模 运算符,但...
自定义的插值公式
1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ACTBook
{
/**
* static function Repeat (t : float, length : float) : float
* 循环数值t,0到length之间。t值永远不会大于length的值,也永远不会小于0。
* 这是类似于 模 运算符,但可以使用浮点数。
*/
public class Tween1 : MonoBehaviour
{
const float TIME = 3f;
const float DISTANCE = 3f;
void Update()
{
var t = Mathf.Repeat(Time.time, TIME) / TIME;
Debug.Log(t);
/**
* static functionLerp (from : float, to : float, t : float) : float
* 基于浮点数t返回a到b之间的插值,t限制在0~1之间。
* 当t = 0返回from,当t = 1 返回to。当t = 0.5 返回from和to的平均值
*/
transform.localPosition = Vector3.Lerp(new Vector3(0f, 0f, 0f), new Vector3(DISTANCE, 0f, 0f), t);
}
}
}
2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ACTBook
{
public class Tween2 : MonoBehaviour
{
const float TIME = 3f;
const float DISTANCE = 3f;
const float SMOOTH_TIME = 0.2f;
Vector3 mVelocity;
void Update()
{
var t = Mathf.Repeat(Time.time, TIME) / TIME;
var target = Vector3.Lerp(new Vector3(0f, 0f, 0f), new Vector3(DISTANCE, 0f, 0f), t);
/**
* public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed = Mathf.Infinity, float deltaTime = Time.deltaTime);
*
* current The current position.
* target The position we are trying to reach.
* currentVelocity The current velocity, this value is modified by the function every time you call it.
* smoothTime Approximately the time it will take to reach the target. A smaller value will reach the target faster.
* maxSpeed Optionally allows you to clamp the maximum speed.
* deltaTime The time since the last call to this function. By default Time.deltaTime.
*
*/
transform.localPosition = Vector3.SmoothDamp(transform.localPosition, target, ref mVelocity, SMOOTH_TIME);
}
}
}
3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ACTBook
{
public class Tween3 : MonoBehaviour
{
const float TIME = 3f;
const float DISTANCE = 3f;
const float SMOOTH_TIME = 0.2f;
Vector3 mVelocity;
void Update()
{
var t = Mathf.Repeat(Time.time, TIME) / TIME;
var quicken_t = t * t;
transform.localPosition = Vector3.Lerp(new Vector3(0f, 0f, 0f), new Vector3(DISTANCE, 0f, 0f), quicken_t);
}
}
}
4
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ACTBook
{
public class Tween4 : MonoBehaviour
{
const float TIME = 3f;
const float DISTANCE = 3f;
void Update()
{
var t = Mathf.Repeat(Time.time, TIME) / TIME;
t = (t - 1f) * (t - 1f) * (t - 1f) + 1f;
t = t * t;
transform.localPosition = Vector3.Lerp(new Vector3(0f, 0f, 0f), new Vector3(DISTANCE, 0f, 0f), t);
}
}
}
本文地址:https://blog.csdn.net/qq_36382679/article/details/107879630
推荐阅读
-
mysql-Mysql存储过程中怎么判断传入参数与自定义字符串的值相等(新人求助)
-
Excel公式的错误值认识及IF+IS函数的容错组合的使用
-
详解VUE中的插值( Interpolation)语法
-
利用opencv提高图像分辨率和降低分辨率(双三次插值),并计算PSNR的值
-
三次样条插值的Matlab
-
Android 入门第十讲02-广播(广播概述,使用方法(系统广播,自定义广播,两个activity之间的交互和传值),EventBus使用方法,数据传递,线程切换,Android的系统广播大全)
-
自定义一个theme在不同的sdk环境下继承不同的值
-
Python实现的拉格朗日插值法示例
-
自定义一个theme在不同的sdk环境下继承不同的值
-
js获取自定义属性的值(如何获取select框的值)