Hi to all,
I mess up with a problem and not able to come out of it.
I want to create a static custom shape (i.e combination of basic shapes).
It must be static as i don't want gravity effect + no effect of collision on it (but not vice versa).
This whole custom shape should be put on a sprite which is performing some action like "Rotation".
I cannot use poly shape on sprite as there are concave poly issue with shapes.
So what should be the idea for doing that.
I am using Spacemanager for this....
Plz help me out....
Combine static shapes or ignore gravity to specific shapes
-
- Posts: 1
- Joined: Sun Nov 07, 2010 12:05 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Combine static shapes or ignore gravity to specific shapes
You can attach multiple shapes to the same rigid body. If you need to make a concave polygon, just attach several convex polygons. As long as you aren't adding 10 shapes per body, the performance is good.
I've never used SpaceManager, but using the C API you want to do something like this:
Because rotatingBody was never added to the space, it won't be updated. This means that it won't get gravity, but it also won't move. Call cpBodyUpdatePosition(rotatingBody, dt) to make it move before calling [space step:dt] or whatever SpaceManager uses to update the space.
I've never used SpaceManager, but using the C API you want to do something like this:
Code: Select all
// INFINITY for mass and moment of inertia so it's not affected by collisions
// Don't add it to the space so it doesn't get any gravity
cpBody rotatingBody = cpBodyNew(INFINITY, INFINITY);
rotatingBody.p = position;
rotatingBody.w = rotationSpeedInRadiansPerSecond;
cpShape *shape;
// add multiple shapes
// they will be moving, so don't add as static shape
shape = cpSpaceAddShape(space, cpCircleShape(rotatingBody, radius, offset));
// set some properties if you want
shape.layers = someLayers;
shape.collision_type = someCollisionType;
// Add more shapes to the same body...
shape = cpSpaceAddShape(space, cpPolyShape(rotatingBody, vertexes, count, someOffset));
shape = cpSpaceAddShape(space, cpPolyShape(rotatingBody, vertexes2, count2, someOffset2));
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 10 guests