当前位置:网站首页>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)
【项目文件】
边栏推荐
- eslint语法规则报错
- Process/Thread related in Sandbox - 1
- Jenkins API groovy调用实践: Jenkins Core Api & Job DSL创建项目
- read stream 特别注意
- NFS 特别注意权限的问题
- GIN中GET POST PUT DELETE请求
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 14 Assignment
- 乐东消防救援大队应邀为干部开展消防安全培训
- Data Mining-06
- 自己做了个nodejs+epxress+mysql的小项目,怎么才能让别人通过互联网访问呢?
猜你喜欢
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)
kustomize入门示例及基本语法使用说明
FPGA中串口通信的时钟频率和波特率计数
Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
搭建大型分布式服务(二)搭建会员服务
5G China unicom repeater network management protocol real-time requirements
5G China unicom AP:B SMS ASCII Transcoding Requirements
How to solve the 0x80070005 error when the computer is reinstalled and the system is restored
WSA toolkit installed app store tip doesn't work how to solve?
GIN Bind mode to get parameters and form validation
随机推荐
一维数组&指针
LeetCode 37. Solve Sudoku
FPGA中串口通信的时钟频率和波特率计数
5G China unicom AP:B SMS ASCII 转码要求
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 15 Homework
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)
[MRCTF2020]套娃-1
Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres
30行代码实现蚂蚁森林自动偷能量
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
Redis源码剖析之跳表(skiplist)
Dry+Bean+Dataset R语言数据分析,报告英文
Redis源码剖析之字典(dict)
快来扔鸡蛋。
ArcEngine(八) 选择要素并高亮显示
面试题精选:神奇的斐波那契数列
正则引擎的几种分类
我的2020年终总结
5G China unicom repeater network management protocol real-time requirements
Clock frequency and baud rate count for serial communication in FPGA