应该设置球的物理特性?

时间:2011-07-04 11:48:12

标签: iphone cocos2d-iphone box2d

正在使用球的物理特性:

  • 高尔夫球

    // Create circle shape
    b2CircleShape circle;
    circle.m_radius = 15.5/PTM_RATIO;
    
    // Create ball shape definition and add to body
    b2FixtureDef ballShapeDef;
    ballShapeDef.shape = &circle;
    ballShapeDef.density = 5000.0f;
    ballShapeDef.friction = 10.0f;
    ballShapeDef.restitution = 0.2f;
    
    ballFixture = ballBody->CreateFixture(&ballShapeDef);
    
  • 赛球

    // Create circle shape
    b2CircleShape circle;
    circle.m_radius = 17.0/PTM_RATIO;
    
    // Create ball shape definition and add to body
    b2FixtureDef ballShapeDef;
    ballShapeDef.shape = &circle;
    ballShapeDef.density = 5000.0f;
    ballShapeDef.friction = 10.0f;
    ballShapeDef.restitution = 0.4f;
    
    ballFixture = ballBody->CreateFixture(&ballShapeDef);
    
  • ironball

    // Create circle shape
    b2CircleShape circle;
    circle.m_radius = 23.0/PTM_RATIO;
    
    // Create ball shape definition and add to body
    b2FixtureDef ballShapeDef;
    ballShapeDef.shape = &circle;
    ballShapeDef.density = 5000.0f;
    ballShapeDef.friction = 10.0f;
    ballShapeDef.restitution = 0.0f;
    
    ballFixture = ballBody->CreateFixture(&ballShapeDef);
    
  • soccerball:

    // Create circle shape
    b2CircleShape circle;
    circle.m_radius = 24.0/PTM_RATIO;
    
    // Create ball shape definition and add to body
    b2FixtureDef ballShapeDef;
    ballShapeDef.shape = &circle;
    ballShapeDef.density = 5000.0f;
    ballShapeDef.friction = 10.0f;
    ballShapeDef.restitution = 0.8f;
    
    ballFixture = ballBody->CreateFixture(&ballShapeDef);
    
  • 篮球:

    // Create circle shape
    b2CircleShape circle;
    circle.m_radius = 24.0/PTM_RATIO;
    
    // Create ball shape definition and add to body
    b2FixtureDef ballShapeDef;
    ballShapeDef.shape = &circle;
    ballShapeDef.density = 5000.0f;
    ballShapeDef.friction = 10.0f;
    ballShapeDef.restitution = 0.6f;        
    ballFixture = ballBody->CreateFixture(&ballShapeDef);
    

作为一个新手,我所有的实施都是基于猜测,我遇到了一些麻烦,比如被困的障碍物,该死的障碍物上的慢动作等等,所以如果有更好的解决方案,请把它们放好。 / p>

2 个答案:

答案 0 :(得分:2)

首先,我建议你不要使用超过100的密度。它会提供不好的模拟。将密度保持在1 - 100的范围内。与动态物体的[0.1,10]范围内的物体大小相同,静态物体的大小最多为50(来自box2d文档)。通常摩擦力设置在0和1之间(也来自box2d文档)。所以你必须在你自己的单位工作,以达到范围。例如,您可以将密度测量为每立方体宽度计的克数。

要评估球的密度,您需要知道它的半径和质量。在这种情况下,您可以找到密度为m / V,其中V是体积。

要测量恢复原状,请在youtube上找一些视频,看看投掷时球的反弹程度。恢复原状是h2 / h1,其中h1初始高度,h2 - 弹跳后的高度

答案 1 :(得分:0)

我认为没有任何真正的答案,你可能不得不选择最适合你的方式。虽然有几条评论:密度极高,摩擦力应在0-1之间,高尔夫球恢复原状实际上相当高。我建议从密度1和约0.5的摩擦开始,然后从那里进行调整。