iDevGames Forums
Chipmunk moonbuggy dynamic landscape - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Chipmunk moonbuggy dynamic landscape (/thread-639.html)



Chipmunk moonbuggy dynamic landscape - wonza - Oct 29, 2009 06:22 AM

I've been playing around with chipmunk and just need a little advice on the best approach. I'm attempting to change the moonbuggy example to use one continious landscape. The current landscape is a series of points created as a static shape, so Im wondering which way would be best:

1) To remove the entire landscape object and replace it with another one.
2) Make the landscape really long and when reaching the end put the view back to the begining again

I dont know how easy it would be to make either method seemless and prevent confusing chipmunk. What do people here think may be best?

Thanks! Smile


Chipmunk moonbuggy dynamic landscape - Skorche - Oct 29, 2009 06:34 AM

Infinite perlin noise terrain moon buggy:
http://howlingmoonsoftware.com/downloads/ByteRacer.zip

Written in mostly in Ruby, which you can see by digging around in the app bundle. Basically it generates chunks of terrain and adds/removes them when they enter/exit the screen. It also wraps the position of the car to keep it near the (0,0) and moves the terrain around it to match. This probably isn't really necessary, but I was playing around.

If you just want looping terrain, I'd just repeat the terrain and wrap the positions of bodies when they get near the ends.


Chipmunk moonbuggy dynamic landscape - wonza - Oct 29, 2009 06:42 AM

Thanks! I'll have a look at that tonight Smile


Chipmunk moonbuggy dynamic landscape - wonza - Nov 5, 2009 01:37 AM

I've successfully managed to get most of this working but I'm having one remaining problem that I cant seem to solve.
The land is created and drawn and matches with the chipmunk shapes etc just fine, you can move forwards and backwards and the next and previous shapes are created and placed in the correct positions. However, if you say move backwards far enough for a new segment to be created in front of you, and move forwards again to where you started, it starts following shapes that should no longer be there. Eventually if you carry on going you will fall back down to where the land really is and be able to continue as normal.

I'm assuming this is due to old shapes not being removed properly, but I cant seem to get it working. I've attacked the relevent parts of my code below. Its either that or I'm not copying landSegments elements over properly, ie its a basic C mistake.

Code:
struct Segment {
    float *points;
    cpShape *myshape[65];
};
typedef struct Segment Segment;

Segment landSegments[3];

updateTerrain() {
    for (int s = midPoint-1; s <= midPoint+1 ; s++) {
        for (int p = 0; p < noOfPointsPerSegment; p++) {
            cpSpaceRemoveStaticShape(space, landSegments[s].myshape[p]);
            cpVect b = cpv(d*50.0f, landSegments[s].points[p]*80.0f);
            landSegments[s].myshape[p] = cpSegmentShapeNew(staticBody, a, b, 0.0f);
            landSegments[s].myshape[p]->u = 1.0;
            cpSpaceAddStaticShape(space, landSegments[s].myshape[p]);
            a = b;
            d+=1.0f;
        }
    }
}


processLand() {
    if (nextSeg)
        landSegments[0] = landSegments[1];
        landSegments[1] = landSegments[2];
        float *noise = createNoise(noOfPointsPerSegment, landSegments[1].points[noOfPointsPerSegment-1], TRUE);
        landSegments[2].points = noise;
        updateTerrain();
    }
    else if (prevSeg) {
        landSegments[2] = landSegments[1];
        landSegments[1] = landSegments[0];
        float *noise = createNoise(noOfPointsPerSegment, landSegments[0].points[0], FALSE);
        landSegments[0].points = noise;
        updateTerrain();
    }
}



Chipmunk moonbuggy dynamic landscape - wonza - Nov 5, 2009 01:47 PM

I'm pretty sure its not to do with copying the arrays incorrectly. I'm sure it has to do with not removing the old shapes in chipmunk.

I've also tried removing all the shapes, re-adding them in a seperate loop and then calling cpSpaceRehashStatic(space); I've tried a few different combinations but none seem to work.

It would be great if anyone has any suggestions


Chipmunk moonbuggy dynamic landscape - wonza - Nov 6, 2009 01:08 AM

Typically, I went to bed and two mins later I solved it Smile