问题与物理和数学 [英] Issue with physics and maths

查看:171
本文介绍了问题与物理和数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要如何实现一个良好的操纵杆在屏幕上移动的物体code例子或指导方针。

I need code examples or guidelines of how to implement a good joystick to move objects in the screen.

推荐答案

有一个叫插补原理 - 本质上,你要通过点点滴滴的两个值之间移动,在你所描述的方式。有很多复杂的方式来做到这一点,但线性插值是最直接的。它的工作原理大致如下:

There is a principle called interpolation - essentially you move between the two values you want bit by bit, in the way you have described. There are plenty of complicated ways to do it, but linear interpolation is the most straightforward. It works roughly as follows:

如果初始速度 A 和最终速度为 B ,你想在两者之间转换,你让你中间的速度是(1-K)*一+ K * B 。 在这里, K 是一个浮点数其从0开始,并结束于1。您可以从EX pression看到,当 K = 0 ,我们中间速度 A ,当 K = 1 的速度变得 B 。当 K 是0和1之间,我们得到的 A 的速度b

If initial velocity is a and final velocity is b and you want to transition between the two, you let your intermediate velocity be (1-k)*a + k*b. Here k is a float which begins at 0, and ends at 1. You can see from the expression that when k=0, our intermediate velocity is a, and when k=1 the velocity becomes b. When k is between 0 and 1, we get a velocity in between a and b.

现在,你只需要选择你想要多久你过渡到最后。这个时候打电话 TTIME 。然后你通过设置 K =(时间距今已有转变开始)/ TTIME)更新 K 。 TTIME的价值是由你 - 它保存为一个区域,然后你可以很容易地调整它,只是尝试一些值,看看有什么感觉对你的游戏

Now you just have to choose how long you want your transition to last. Call this time tTime. Then you update k by setting k = (time elapsed since transition started) / tTime). The value of tTime is up to you - store it as a field and then you can easily tweak it, just try some values and see what feels right for your game

该原则在有些描述更详细的这里

The principles are described in a bit more detail here

这篇关于问题与物理和数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆