统一运动触摸

编程入门 行业动态 更新时间:2024-10-27 20:36:17
本文介绍了统一运动触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在做一个足球点球如游戏,我需要移动球移动了。现在,我使用这个代码:

I'm making a football-penalty like game and I need to move the ball on mobile too. I'm using this code now:

float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rigidbody.AddForce(movement * speed * Time.deltaTime);

我怎样才能使运动系统,移动?

How can i make a movement System For mobile?

此外,还有就是控制球(当你通过一条线(就像保龄球一样),你只能改变它的位置1/10)someother代码。但他们都是基于这个代码...游戏脚本是C#...

Also, there is someother codes that control the ball (like when you pass a line (just like bowling) you can only change it's place 1/10). But they are based on this code... Game script is c#...

推荐答案

使用轴触摸开关,这将有点困难。我建议阅读有关Touchscript( interactivelab.github.io/TouchScript/ )以及如何API的工作一般。你会需要做的就是当玩家触摸屏幕,你缓存联系,当他们碰你直呼其触摸比较其当前位置测量运动的方向。 。通过这样做,你可以刷卡路线

Switching this from using axis to touch will be a bit difficult. I recommend reading about Touchscript (interactivelab.github.io/TouchScript/) and how the API works in general. What you're going to need to do is when the player touches the screen, you cache that touch and while they're touching you measure the direction of the movement by comparing their first touch to their current position. By doing this you can get swipe directions.

像这样的东西可以让你开始:

Something like this could get you started:

public void OnTouchBegin( object sender, TouchEventArgs e ){ foreach( TouchPoint point in e.TouchPoints ){ firstTouchPosition = new Vector2( point.Position.x, point.Position.y ); } } public void OnTouchContinue( object sender, TouchEventArgs e ){ foreach( var point in e.TouchPoints ){ secondTouchPosition = new Vector2( point.Position.x, point.Position.y ); currentTouchMovement = new Vector2( ( secondTouchPosition.x - firstTouchPosition.x ), ( secondTouchPosition.y - firstTouchPosition.y )); currentTouchMovement.Normalize( ); } } public void OnTouchEnd( object sender, TouchEventArgs e ){ hasTouchEnded = true; }

和你需要一些自定义代码来确定X和Y轴方向与触摸输入相对应。另外要小心屏幕坐标和游戏中的坐标为它们之间的区别相当多。这看起来令人生畏在第一,但也有一些工作,我保证它不是太糟糕了!希望这有助于!

And you'll need some custom code to determine the X and Y axis direction corresponds with the touch input. Also be careful about screen coordinates and in-game coordinates as they differ quite a bit. This looks daunting at first, but with some work I promise its not too bad! Hope this helps!

更多推荐

统一运动触摸

本文发布于:2023-06-10 18:33:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/616443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!