博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于站在移动物上的问题
阅读量:6858 次
发布时间:2019-06-26

本文共 1293 字,大约阅读时间需要 4 分钟。

游戏中经常遇到在移动物上战斗的情况,而直接拖拽的话就会下落了

 

 

默认情况:

 

 

比较简单的办法是直接设置父物体

 

 

但刨根问底想一下,在Unity里拖拽,使用transform移动,其实都不是基于物理的移动

只有改变速率才是,后来用恒力去测了一下,果然可以带动站在上面的物体

 

所以,我尝试了一下更简单的方式

 

脚本:

using UnityEngine;using System.Collections;public class PhysicsTest : MonoBehaviour{    const int MAX_MASS = 10000;    void Awake()    {        GetComponent
().mass = MAX_MASS; GetComponent
().material = new PhysicMaterial(); GetComponent
().material.staticFriction = 99999; GetComponent
().material.dynamicFriction = 99999; } IEnumerator Start() { while (true) { for (int i = 0; i < 100; i++) { GetComponent
().velocity = Vector3.right * Time.deltaTime * 1000f; yield return new WaitForFixedUpdate(); } yield return new WaitForSeconds(1); for (int i = 0; i < 100; i++) { GetComponent
().velocity = -Vector3.right * Time.deltaTime * 1000f; yield return new WaitForFixedUpdate(); } yield return new WaitForSeconds(1); } }}
View Code

 

这样用在横版游戏中很便捷,可以避开不少bug

但是对于3D游戏的飞机或者火车顶上的移动比较麻烦,载具的驱动方式很复杂,还是改父物体比较好

转载于:https://www.cnblogs.com/hont/p/5796895.html

你可能感兴趣的文章
Linux系统各个目录的一般作用
查看>>
maven安装与配置
查看>>
Windows Phone 8 开发环境配置(记录)
查看>>
MVC
查看>>
使用重置按钮,重置表单信息
查看>>
在指定时间干,必须干(kbmmw 中的事件调度)
查看>>
通过微信查找SAP TCODE代码
查看>>
c 二叉树的使用
查看>>
分分钟解决iOS开发中App启动广告的功能
查看>>
Helpers\Assets
查看>>
Thrift安装问题
查看>>
周末聊聊IT人员的人脉观:关于帮妹子找兼职有感
查看>>
InvokeRequired和Invoke
查看>>
IIS 之 通过 Web.config 修改文件上传大小限制设置方法
查看>>
MongoDB_C_Driver使用教程(2)高级连接
查看>>
Linux常用命令大全
查看>>
JavaScript:下拉列表框的事件处理
查看>>
ASP.NET Aries 3.0发布(附带通用API设计及基本教程介绍)
查看>>
jQuery EasyUI实现关闭全部tabs
查看>>
poj3635Full Tank?[分层图最短路]
查看>>