我有关于空中速度的问题。
当我同时跳跃并移动时,玩家的时间速度会增加。我使用冲动进行跳跃,并使用力进行移动。我想知道当玩家在空中时如何放慢速度。
这是我左右移动的代码
-(void)update:(ccTime)dt :(b2Body *)ballBody :(CCSprite *)player1 :(b2World *)world
{
if (moveRight.active==YES)
{
// maxSpeed=10.0f;
ballBody->SetActive(true);
// b2Vec2 locationworld=b2Vec2(maxSpeed,0);
double mass=ballBody->GetMass();
ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
ballBody->SetLinearDamping(1.2f);
}
else if(moveLeft.active==YES)
{
ballBody->SetActive(true);
b2Vec2 locationworld=b2Vec2(-10,0);
double mass=ballBody->GetMass();
ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
// ballBody->SetLinearDamping(1.2f);
}
}
以下是跳跃玩家
-(void)jump:(b2Body*)ballBody:(ccTime)dt:(BOOL)touch
{
if (touch)
{
if (jumpSprte.active==YES)
{
ballBody->SetActive(true);
b2Vec2 locationWorld;
locationWorld=b2Vec2(0,25);
ballBody->ApplyLinearImpulse(locationWorld, ballBody->GetWorldCenter());
}
}
}
所以我在哪里使用逻辑?
提前致谢
答案 0 :(得分:1)
你需要模拟空气阻力,以减慢播放器在空中的速度。有几种方法可以实现这一点,具体取决于您希望模拟的真实程度。对于一个简单的模型linearDampening
会降低它的速度。
真正的空气阻力不是线性的。要以更现实的方式对此进行建模,您需要使用以下内容:
F = - C * v * |v|
F
是空气阻力的总力量C
是一个取决于对象形状的拖动常量v
是速度向量(|v|
是速度的大小,或长度,如果你愿意的话)听起来你的玩家还可以在空中使用移动来提高速度。这是因为你允许玩家在他的腿不接触地面时施加力量。如果这是你的目标,为了禁止这一点,请确保当角色接触地面时,唯一可以施加更多力量使其移动的时间。
请注意,这一切都取决于您希望这种类型的游戏。如果在为游戏制作物理时看起来感觉很好,那么就是好的。如果你不能设法完全准确地模拟现实,只要最终结果能够很好地发挥作用,就不要紧张。
答案 1 :(得分:0)
这是我左右移动的代码
-(void)update:(ccTime)dt :(b2Body *)ballBody :(CCSprite *)player1 :(b2World *)world
{
if (moveRight.active==YES)
{
// maxSpeed=10.0f;
ballBody->SetActive(true);
// b2Vec2 locationworld=b2Vec2(maxSpeed,0);
double mass=ballBody->GetMass();
ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
ballBody->SetLinearDamping(1.2f);
}
else if(moveLeft.active==YES)
{
ballBody->SetActive(true);
b2Vec2 locationworld=b2Vec2(-10,0);
double mass=ballBody->GetMass();
ballBody->ApplyForce(mass*locationworld, ballBody->GetWorldCenter());
// ballBody->SetLinearDamping(1.2f);
}
}
以下是跳跃玩家
-(void)jump:(b2Body*)ballBody:(ccTime)dt:(BOOL)touch
{
if (touch)
{
if (jumpSprte.active==YES)
{
ballBody->SetActive(true);
b2Vec2 locationWorld;
locationWorld=b2Vec2(0,25);
ballBody->ApplyLinearImpulse(locationWorld, ballBody->GetWorldCenter());
}
}
}
所以我在哪里使用逻辑?