c# - 如何通过触摸在屏幕上拖动手指来移动 3D 对象
问题描述
我想通过触摸来移动对象 在屏幕上拖动手指意味着对象应该跟随手指的方向 我在 Play Store 上找到了一个游戏,该游戏球通过触摸它来左右移动,这正是我想要在我的游戏中制作的内容 我的链接游戏:- https://play.google.com/store/apps/details?id=com.ketchapp.hop
解决方案
最简单的做法是将玩家手指在屏幕上的位置设置为一个世界点,并将该世界点设置为 Vector3。将球移动到世界点 Vector3(假设您想使用速度来移动,否则只需使用 .position)。
//Variables
public transform ball;
public float speed = 10f;
//i do not know about touch screen controls. this is something i will link to below!
//Get Touch Position
Vector3 worldTouchPos = screenTouchPos; //worldTouchPos = the touch position in world space, and the screenTouchPos is the touch position on the screen ( so a value between 0 and 1 in both x and y).
//Ball Movement
ball.position = Vector3.MoveTowards(ball.position //pos to move from\\ ,worldTouchPos //pos to move to\\, speed);
触摸控制链接到 YT 视频:Brackeys 视频,/您想观看的其他视频!!!
推荐阅读
- flutter - 跨应用程序的 Flutter Firebase 用户身份验证管理
- python - 检查值是否在列表中的更好方法?
- python - 如何使用漂亮的汤禁用不在列表中的所有链接
- python - 在 Scrapy 中使用字体或颜色抓取网站
- python - python求解字符串内的方程
- javascript - Expressjs:如何使用多个查询字符串正确搜索?
- javafx - 无法通过另一个控制器控制另一个 fxml 文件的元素
- typescript - 使用原型向 Typescript 类添加方法
- python - 想将pygame项目转换为windows可执行文件
- dropwizard - Dropwizard 应用集成测试,DropwizardAppRule 端口为空