我怎么能限制冲动?我希望身体快速跳跃,然后限制他的跳跃。
我正在寻找类似下面的东西,冲动后的摩擦,但这不起作用(玩家停留在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);
答案 0 :(得分: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;
}