1

I want to create game like Roller Coaster and try to make Train for it..

I have tried created train with boxbody

code for train :

-(void)addTrainAtPos:(CGPoint)pos:(int)n:(CCLayer *)Layer
{
    b2BodyDef BodyDef;
    BodyDef.type = b2_dynamicBody;

    b2PolygonShape box;
    b2FixtureDef fixtureDef;

    fixtureDef.density = 0.5f;
    fixtureDef.friction = 0.0f;
    fixtureDef.restitution = 0.0f;

    box.SetAsBox(ptm(15), ptm(10));
    fixtureDef.shape = &box;

    b2Body *Body;
    b2Body *LastBody;

    b2DistanceJointDef Djoint;

    BodyDef.position.Set(ptm(pos.x - (0 * (30 + Spacing))), ptm(pos.y));
    BodyDef.fixedRotation = true;
    Body = world->CreateBody(&BodyDef);
    Body->CreateFixture(&fixtureDef);

    LastBody = Body;

    for (int i=1; i<n; i++) 
    {
        BodyDef.position.Set(ptm(pos.x - (i * (30 + Spacing))), ptm(pos.y));
        BodyDef.fixedRotation = true;
        Body = world->CreateBody(&BodyDef);
        Body->CreateFixture(&fixtureDef);

        //Djoint.Initialize(LastBody, Body, LastBody->GetWorldCenter(), Body->GetWorldCenter());
        //world->CreateJoint(&Djoint);
        //LastBody = Body;

    }

}

I also tried to Create Joint Between trains and try to move it with continue LinearVelocity

-(void)MoveTrain
{
    for(NSValue *Val in Bodies)
    {
        b2Body *Body = (b2Body *)[Val pointerValue];
        b2Vec2 old = Body->GetLinearVelocity();
        if(old.x < 20)
            Body->SetLinearVelocity(b2Vec2(Speed, old.y));
    }
}

But my problem is that when i jump the train i apply force to first engine but my whole train not jumped perfectly than i tried to apply force to whole train one by one all bogie in some delay but also i not get perfect so please give me any related code to create Train and move and jump it perfectly..

Devang
  • 61
  • 3
  • Am I right to assume that you're trying to create something similar to Tiny Wings but with a train? You will have to experiment a lot if you want to get it right, I doubt anyone can give you a simple solution that works. You could try to reduce mass of the bodies, you could run the train at higher speed, you could try and fake physics (a lot of games do) by applying unrealistic forces in certain cases. It's hard to suggest something that'll work in your case, tweaking physics is just a lot of trial and error. – CodeSmile Jul 14 '12 at 09:43
  • I tried so many diff physics but i not get any that i want.. I want to make this type of game http://itunes.apple.com/us/app/madcoaster/id476279186?mt=8 , please give me any demo code if any available or any hint that how i create train physics – Devang Jul 14 '12 at 09:56
  • I'm not so sure that game even uses physics. – iforce2d Jul 14 '12 at 16:25
  • Am also think that they are not uses physics and i tried without physics but i m not success so please give me any block of code which make train like in this game.. with physics or without.. – Devang Jul 16 '12 at 12:57

0 Answers0