2012-06-30 6 views
0

어떻게 충격을 제한 할 수 있습니까? 나는 시체가 빨리 뛰어 오르고, 그 후에 그의 점프를 제한하고 싶다.box2d에서 점프 후 충동을 제한하는 방법은 무엇입니까?

난 다음, 충동 후 마찰 같은 것을 찾고 있어요 그러나 이것은 (vec2.y가 "0"과 동일하므로 플레이어가, y 축에서의 위치에 유지)

작동하지 않습니다
//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

이 어쩌면 당신은 몸이 수직 방향으로 이동하는 속도를 보면, 그 때마다에 작은 힘 반대를 적용 할 수 단계. – iforce2d

+0

@ iforce2d 감사합니다. 어떻게하실 수 있습니까? – Paul

답변

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; 
} 
관련 문제