当前位置:网站首页>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)
【项目文件】
边栏推荐
- GET POST PUT DELETE request in GIN
- 5G 联通网管设计思路
- 正则表达式-re模块
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
- 安踏携手华为运动健康共同验证冠军跑鞋 创新引领中国体育
- Periodic sharing of Alibaba Da Tao system model governance
- 【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
- 十进制数字→十六进制字符
- 基于 R 语言的判别分析介绍与实践 LDA和QDA
- 为什么文字不贴合边
猜你喜欢
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
19、学习MySQL 索引
Unicom network management protocol block diagram
FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)
蓝桥杯线上模拟赛——Flex 经典骰子布局
eslint语法规则报错
安踏携手华为运动健康共同验证冠军跑鞋 创新引领中国体育
GET POST PUT DELETE request in GIN
FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)
jenkins api create custom pipeline
随机推荐
WPF 实现带蒙版的 MessageBox 消息提示框
GIN Bind mode to get parameters and form validation
5G China unicom 直放站 网管协议 实时性要求
IDEA Gradle 常遇问题(一)
5G China unicom repeater network management protocol real-time requirements
Sandbox中的进程/线程相关-2
Unicom network management protocol block diagram
30行代码实现微信朋友圈自动点赞
ArcEngine(十)创建矢量图层
陈强教授《机器学习及R应用》课程 第十四章作业
#WeArePlay | 与更多开发者一起,探索新世界
Data Mining-06
Final assignment of R language data analysis in a university
JS动画函数封装
面试攻略系列(二)-- 秒杀系统
Process/Thread related in Sandbox - 1
Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
ftplib+ tqdm upload and download progress bar
kustomize entry example and basic syntax instructions
Sandbox中的进程/线程相关-1