void Move::OnUpdate(float elapsedTime) { EntityPtr e = GetEntity(); float ds = 1.0f; Vector2 v(cos(mAngle) * mSpeed * ds , sin(mAngle) * mSpeed * ds); b2Body* body = ((Box2DBody*)e->GetBody())->GetBox2DBody(); //body->SetLinearVelocity(v); v.x *= body->GetMass() * 10; v.y *= body->GetMass() * 10; body->ApplyForce(v, e->GetPosition()); Vector2 cv = body->GetLinearVelocity(); float fv = abs(cv.Length()); if (fv > abs(mSpeed) && fv > 0.00001) { cv.x *= abs(mSpeed) / fv; cv.y *= abs(mSpeed) / fv; body->SetLinearVelocity(cv); } }
void Move::OnDone() { if (mChannel) Engine::GetSingleton()->GetSoundSystem()->StopChannel(mChannel); EntityPtr e = GetEntity(); Vector2 v(0.0f, 0.0f); if (e != 0) e->GetBody()->SetLinearVelocity(v); }