Box2D的:最大可能的线速度? [英] Box2d: Maximum possible linear velocity?

查看:784
本文介绍了Box2D的:最大可能的线速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我已经配置的Box2D有某种为任何机构的最大速度,但我不知道。我申请喜欢冲动(亿,100000000),和机身一样快,移动为(100,100) - 这是不是很快在所有

I think I've configured Box2d to have some sort of maximum velocity for any body, but I'm not sure. I apply an impulse like (100000000, 100000000), and the body moves just as fast as (100, 100) - which is not that fast at all.

我使用的是Box2D的XNA C#端口

I'm using the Box2d XNA C# port.

我的。 。游戏是一个自上而下的2D

My game is a top-down 2d.

下面是一些代码,可能是相关的:

Here is some code that may be relevant:

private readonly Vector2 GRAVITY = new Vector2(0, 0);

    public void initializePhysics(ContactReporter contactReporter)
    {
        world = new World(GRAVITY, true);
        IContactListener contactListener = contactReporter;
        world.ContactListener = contactListener;
    }

    public void Update(GameTime gameTime)
        {
     // ...

            worldState.PhysicsWorld.Step((float)gameTime.ElapsedGameTime.TotalSeconds, 10, 10);

     //...
        }

下面是一些适用冲动示例代码:

Here is some example code that applies the impulse:

    private void ApplyImpulseFromInput()
    {
        Vector2 movementImpulse = new Vector2();

        if (inputReader.ControlActivation(ActionInputType.MOVE_LEFT) == 1f)
        {
            movementImpulse.X = -Constants.PLAYER_IMPULSE_CONSTANT;
        } else if (inputReader.ControlActivation(ActionInputType.MOVE_RIGHT) == 1f)
        {
            movementImpulse.X = Constants.PLAYER_IMPULSE_CONSTANT; ;
        }

        if (inputReader.ControlActivation(ActionInputType.MOVE_UP) == 1f)
        {
            movementImpulse.Y = -Constants.PLAYER_IMPULSE_CONSTANT; ;
        } else if (inputReader.ControlActivation(ActionInputType.MOVE_DOWN) == 1f)
        {
            movementImpulse.Y = Constants.PLAYER_IMPULSE_CONSTANT; ;
        }

        model.Body.ApplyImpulse(movementImpulse, model.Position);
    }

如果 Constants.PLAYER_IMPULSE_CONSTANT 是任何地方从 1000F 1000000000f ,玩家最多可(移动 - 120, -120)(120,120)。如果常数较小,如 1F ,玩家将更加缓慢移动。

If Constants.PLAYER_IMPULSE_CONSTANT is anywhere from 1000f to 1000000000f, the player can move at most (-120, -120) to (120, 120). If the constant is less, like 1f, the player will move more slowly.

这代码是用来设置物理起来在游戏世界的一切:

This code is used to set up physics for everything in the game world:

        controller.Model.BodyDef = new BodyDef();
        controller.Model.BodyDef.type = controller.Model.Mobile ? BodyType.Dynamic : BodyType.Static;
        controller.Model.Body = worldState.PhysicsWorld.CreateBody(controller.Model.BodyDef);
        controller.Model.Body.SetLinearDamping(10.0f);



难道可能被线性衰减?我改变了它从 10.0f 0 ,没有效果。

更新:怪诞线性阻尼:我已经在身体上这些意见,即移动与上面的应用脉冲法:

UPDATE: Weirdness with linear damping: I have made these observations on the body that is moved with the apply impulse method above:

Linear Damping       Max Speed
0f                   120
10f                  120
50f                  120
55f                  90
60f                  0
70f                  0
100f                 0
100000f              0

为什么会出现一系列的线性灵敏度之间的 50F 60F

Why is there a range of sensitivity in linear damping between 50f and 60f?

推荐答案

我有一个版本2.1A
I同样的问题发现,在b2Settings.as变化的线路128可以提供帮助。
变动静态公共常量b2_maxTranslation:数= 2.0到一个更高的数字。
肯定,这是不正确的做法,但现在真的不知道该怎么做是正确的。

I have the same problem with version 2.1a i found out that changing line 128 in b2Settings.as can help. Change static public const b2_maxTranslation:Number = 2.0 to a higher number. sure that this isn't the right way, but right now dont really know how to do it correctly.

这篇关于Box2D的:最大可能的线速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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