2D游戏控制问题-旋转&旋转移动

发布于 2024-11-13 23:36:17 字数 541 浏览 0 评论 0原文

我想知道是否有人可以帮助我开始或指出正确的方向。我正在寻找使用核心动画制作一个简单的驾驶游戏。我是一个相当优秀的 obj-c 程序员,但是当涉及到运动和数学时,我失败了。我想要一个方向盘来控制汽车的方向,以及一个前进/后退来控制加速度和方向。减速。如果有人能帮助我获得方向盘代码,我将不胜感激!所以基本上我需要帮助制作一个可以用 1 根手指拖动旋转的圆圈,我会将它的变换值传递到我的汽车视图(我想我可以处理加速/减速代码)有人接受吗? :) 另外,我有 2 个 dribbble.com 的邀请可以赠送,任何帮助我的人,我很乐意赠送一张。


grady,totowtwo,谢谢你们的回答,我很感激。我已经达到了这样的程度:我可以旋转“方向盘”,它会旋转我的“汽车”,我还可以让它向前和向后移动。只需要变得更加现实...这是 xCode 项目的链接,http://www.cl .ly/7VBU,使其非常简单,因此如果有人查看它 - 更改/添加代码将很容易。所以,如果有人想看看它,并帮助我让这个动作更加真实,我将永远感激你! :) 谢谢!

I was wondering if anyone could help me get started or pointed in the right direction. I'm looking to make a simple driving game using core animation. I'm a pretty good obj-c programmer, but when it comes to movement and math, I fail. I want a steering wheel to control the direction of the car, and a forward/backward to control acceleration & deceleration. If anyone can help me with the steering wheel code, I would be greatly appreciated! So basically I need help making a circle that can rotate with 1 finger drag, and i'll pass it's transform values to my car view ( i think i can handle the accel/deccel code) Any takers? :) Also, I have 2 invites for dribbble.com to give away, anyone who helps me, id be glad to give one out to.


grady, totowtwo, thanks for both your answers, I appreciate it. I;ve gotten to the point where I can rotate a "steering wheel" and it will rotate my "car", I also got it to move forwards and backwards. Just need to moving to be more realistic... Here is a link to the xCode project, http://www.cl.ly/7VBU, kept it very simple so if anyone looks at it - it will be easy to change / add code. So, if anyones wants to look at it,and help me make the movement more realistic, i'd be forever in your debt! :) thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你列表最软的妹 2024-11-20 23:36:17

首先要认识到典型的汽车方向盘具有 900 度的移动角度,无论您是否想要指轮,这都是一个设计决定。在车轮最大旋转时,汽车的车轮通常偏离+z 约 30 度。您可以使用从方向盘角度到车轮角度的简单线性变换。

由此看来,汽车增量角是车轮角度乘以前进距离的函数。当汽车向前行驶时,您可以想象一下,当您笔直指向前方时,您可以追踪一个半径无限大的圆的切线,而当方向盘完全倾斜时,则可以追踪一个半径较小的圆(约 4 倍车长)。

当然,您可以随意放弃典型车辆的设计规则。为您的用户提供像完整机器人一样有趣的传动系统!

A starting point would be to recognize that a typical car steering wheel has 900 degrees of movement, whether you want that for the finger wheel or not is a design decision. The wheels in a car typically point about 30 degrees off +z at maximum rotation of the wheel. You could use a simple linear transformation from steering wheel angle to wheel angle.

From there, Car delta angle is a function of wheel angle times forward distance. As the car moves forward, you can imagine tracing the tangent of a circle with an infinite radius when you are pointing straight ahead, and a circle of smaller radius (~4x car length) when steering wheel is full tilt.

Of course, feel free to discard the design rules of typical vehicles. Give your users fun drive trains like holonomic robots have!

话少心凉 2024-11-20 23:36:17

我不是专家,但你可能会这样做:

CGPoint centerOfWheel;
CGPoint currentTouchPoint;
float radians = atan2(currentTouchPoint.x-centerOfWheel.x, currentTouchPoint.y-centerOfWheel.y);

然后将变换应用到轮子上......当然,你会希望使变换在一定距离的视图上累积,因为持续转动轮子将导致继续转动。

另外,为了让它感觉更真实,反应性更小,您可能需要使用较小的转弯角度,这样车轮转动一圈不会导致车辆转动一整圈。你将不得不玩耍。

I am no expert but you could probably do something like:

CGPoint centerOfWheel;
CGPoint currentTouchPoint;
float radians = atan2(currentTouchPoint.x-centerOfWheel.x, currentTouchPoint.y-centerOfWheel.y);

then apply the transformation to the wheel ... of course you will want to make the transformations cumulative on the view over a distance, as continued turning of the wheel will result in continued turning.

also to make it feel more real, and less responsive you may want to use a lesser degree of turn, so that turning the wheel in once circle doesn't result in a whole circle turn of the vehicle. you will have to play around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文