当前位置:网站首页>01_iTween_第一天--小球抛物线
01_iTween_第一天--小球抛物线
2022-08-09 13:02:00 【MOVCat】
实现小球的抛物线,结果如下:

【实现策略】
1.小球的初始位置为面板中心Vector.zero
2.射线检测出与面板的碰撞点确定小球的抛物落点
3.小球需要在XZ、Y上分别移动
4.
4.1小球在Y轴上产生抛物线效果
4.2小球在XY面直线移动;a+b融合=小球抛物运动
5.iTween的移动方法没有多动画融合需要设定两个不同的命令堆来使物体运动如MoveBy MoveTo --全部命令堆方法链接,中英对照离线文档
5.1.小球模型结构:父物件为空利用命令堆MoveTo,子物件子物件为预置Sphere球体利用命令堆MoveBy
5.2.MoveBy MoveTo与其他命令方法作用只是将设定参数分别加入到不同的命令堆中,再由iTween中的委托方法分别调用,区别方法是利用iTween中的Method参数不同MoveBy 是 "by"值,Moveto是"to"值,FadeTo是"color"值,后续不在阐述可自行参看iTween源码
【场景布置】
地面


落点位置显示图标


游戏控制者初始化

小球结构

【源代码】
public class GameController : MonoBehaviour {
public Transform target; //小球落点图标
public GameObject bomb; //小球模型
void Update()
{
RaycastHit hit = new RaycastHit();
Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(cameraRay.origin, cameraRay.direction, out hit, 100))
{
target.position = new Vector3(hit.point.x, 0.1f,hit.point.z);
}
if (Input.GetMouseButtonDown(0))
{
GameObject newBomb = Instantiate(bomb);
Bomb newBombScript = newBomb.GetComponent<Bomb>();
newBombScript.targetPosition = target.position;
newBombScript.StartDo();
}
}
}public class Bomb : MonoBehaviour {
public GameObject core;
float lobHeight = 4;
float lobTime = 0.7f;
public Vector3 targetPosition;
public void StartDo() {
iTween.MoveBy(core, iTween.Hash("y", lobHeight, "time", lobTime / 2, "easeType", iTween.EaseType.easeOutQuad));
iTween.MoveBy(core, iTween.Hash("y", -lobHeight, "time", lobTime / 2, "delay", lobTime / 2, "easeType", iTween.EaseType.easeInCubic));
iTween.MoveTo(gameObject, iTween.Hash("position", targetPosition, "time", lobTime, "easeType", iTween.EaseType.linear));
iTween.FadeTo(gameObject, iTween.Hash("delay", 3, "time", .5, "alpha", 0, "onComplete", "CleanUp"));
}
void CleanUp()
{
Destroy(this.gameObject);
}
} 主要方法解释:
将提供的amount坐标设定到target对象的移动位置移动花费time量的时间;支持哈希值设定全部命令。
MoveBy(GameObject target, Vector3 amount, float time)
MoveBy(GameObject target, Hashtable args)
将游戏对象target的位置随时间time更改为提供的目的地position;支持哈希值设定全部命令。
MoveTo(GameObject target, Vector3 position, float time)
MoveTo(GameObject target, Hashtable args)
随着时间的推移,改变游戏对象的 alpha 值。 如果附加 Light,GUIText 或 GUIText 组件,它将成为动画的目标;支持哈希值设定全部命令。
FadeTo(GameObject target, float alpha, float time)
FadeTo(GameObject target, Hashtable args)【项目文件】
边栏推荐
猜你喜欢

GIN a preliminary study, the environment is installed

Uni - app - uview Swiper shuffling figure component, click on the links to jump (click to get the item after the row data, remove data operation)

5G China unicom repeater network management protocol real-time requirements

30行代码实现蚂蚁森林自动偷能量

Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres

绘制混合密度函数图以及添加分位数线

uni-app - uview Swiper 轮播图组件点击跳转链接(点击后拿到 item 行数据, 取出数据做操作)

联通网管协议框图

我的2020年终总结

19、学习MySQL 索引
随机推荐
蓝桥杯线上模拟赛——Flex 经典骰子布局
#WeArePlay | 与更多开发者一起,探索新世界
剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
记录本项目中用到的系统调用与C库函数-2
telnet+ftp to control and upgrade the device
【NVIDIA】Tesla V100安装NVIDIA-Driver驱动程序适配CUDA-Toolkit-11.6
陈强教授《机器学习及R应用》课程 第十七章作业
Map mixed density function and quantile added line
搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)
Redis源码剖析之数据过期(expire)
从NPU-SLAM-EDA技术分析
面试攻略系列(二)-- 秒杀系统
ftplib+ tqdm upload and download progress bar
FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)
FFmpeg multimedia file processing (ffmpeg prints audio and video Meta information)
NFS pays special attention to the problem of permissions
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面(循环不变量)
Redis源码剖析之字典(dict)
用plot_hist_numeric()实现画直方图