0

我怎么能限制冲动?我想让身体快速跳跃,然后限制他的跳跃。

我正在寻找类似以下的东西,冲动后的摩擦,但这不起作用(玩家停留在 y 轴上的位置,因为 vec2.y 将等于“0”)

//after a touch
body->ApplyLinearImpulse( b2Vec2(x,y), body->GetPosition() );
vec2 = body->GetLinearVelocity();

//in the tick method, called every step
vec2.y = vec2.y * 0.99;
CCLOG(@"vec2.y : %f", vec2.y);
body->SetLinearVelocity(vec2);
4

1 回答 1

0

我一直在寻找这种安静,但最终做到了:

//call this after touch
       body->ApplyLinearImpulse(b2Vec2(0, 35000), body->GetPosition());

        [self schedule:@selector(CheckVelocity) interval:0.0001];
        [self scheduleOnce:@selector(toggleCheckForLanding) delay:.5];


-(void)CheckVelocity
{
set a max velocity according to your jump i have set it 13.....
    int velocitymax = MAX_VELOCITY;//13
    b2Vec2 vel = body->GetLinearVelocity();
    if(vel.y>velocitymax)
    {
        vel.x = 0;
        vel.y = MAX_VELOCITY;
        body->SetLinearVelocity( vel );
    }

}


-(void) toggleCheckForLanding
{
    [self unschedule:@selector(CheckVelocity)];
    canCheckForLanding_ = YES;
}
于 2015-01-02T13:40:20.603 回答