cocos2d / cocos2d-objc

Cocos2d for iOS and OS X, built using Objective-C
http://www.cocos2d-objc.org
Other
4.07k stars 1.16k forks source link

CCPhysics Enhancements #479

Open slembcke opened 10 years ago

slembcke commented 10 years ago

Smooth Segment Collisions. (easy-ish?)

Chipmunk supports "smooth" line segment collisions, where you give a segment information about it's neighbors and it prevents you from colliding with the cracks between the segments. The deferred nature of CCPhysics made this a little awkward to support so I shelved the feature temporarily. I had an idea to support this with a new Chipmunk feature.

Optional CCPhysicsNodes (easy-ish?)

Have already gotten some feedback that people don't like CCPhysicsNodes or don't understand why they exist. Fair enough. Requiring them may have been a bad idea instead of making them optional.

My current thought to fix it is to move much of the CCPhysicsNode functionality to a separate CCPhysicsSpace object. Make a protocol with a property to return a CCPhysicsSpace object. Make CCPhysicsNode and CCScene implement the protocol. Then every scene already has everything it needs to support CCPhysics without having to make a CCPhysicsNode, but at the same time it's still possible to create extra CCPhysicsNode instances.

Physics Grabbing. (Easy)

ChipmunkMultiGrab is a pretty handy utility class. It allows you to implement multi-touch physics interaction fairly easily. There is a push and a pull mode to it, and they are mutually inclusive. The pull mode is the more obvious of the two. When you touch a shape it will add a joint to it and let you drag it around the screen. Push mode happens when you touch the screen where there isn't a shape. Instead it adds one for your finger so you can nudge other shapes around. So basically it implements the two ways that you would interact with objects laying on a table using your finger. It's all properly force limited and works using constraints so it's fairly hard to break it.

I think this might be as easy as CCPhysicsGrabNode subclass, overriding hitTestWithWorldPos: and implementing the CCResponder methods to pass the touches on to ChipmunkMultiGrab.

Kinematic Bodies. (easy)

The code for this already exists, and is only commented out of the public API because there was a lot of confusion about what kinematic bodies were.

Interpolation. (medium)

Currently there are no options for interpolating rigid body positions for the non-fixed update loop. It's probable that people are going to run into issues with the motion of their physics stuttering even if the framerate is smooth if they start playing around with fixed update settings. Avoiding this would be a good thing.

This isn't too hard to implement, though making it work along with actions makes it much harder.

Joints. (indeterminate)

CCPhysics only supports a basic set of joints. I was conservative about adding more joint types because they are a real pain to support and document all of the different variations that are already in Chipmunk. I implemented the four most common joints from Chipmunk.

I have some potentially big ideas about configurable joints in Chipmunk that might change how I want to go forward with them in CCPhysics.

Projectile Bodies. (medium)

A body with a ray query instead of a shape. This allows for very cheap swept collision bullets without the expense of full swept collisions. I haven't figured out a sensible way for this to fit in with the regular collision delegates though.

Actions. (hard)

There has already been a lot of discussion about this here: https://github.com/cocos2d/cocos2d-iphone/issues/381. Short summary is that actions and physics integrate together in Cocos as poorly as the equivalent features in SpriteKit or Unity. There is a lot of room for improvement.

dissidently commented 10 years ago

Where do I pay for these?

On Mon, Jan 6, 2014 at 4:16 PM, slembcke notifications@github.com wrote:

Smooth Segment Collisions. (easy-ish?)

Chipmunk supports "smooth" line segment collisions, where you give a segment information about it's neighbors and it prevents you from colliding with the cracks between the segments. The deferred nature of CCPhysics made this a little awkward to support so I shelved the feature temporarily. I had an idea to support this with a new Chipmunk feature. Optional CCPhysicsNodes (easy-ish?)

Have already gotten some feedback that people don't like CCPhysicsNodes or don't understand why they exist. Fair enough. Requiring them may have been a bad idea instead of making them optional.

My current thought to fix it is to move much of the CCPhysicsNode functionality to a separate CCPhysicsSpace object. Make a protocol with a property to return a CCPhysicsSpace object. Make CCPhysicsNode and CCScene implement the protocol. Then every scene already has everything it needs to support CCPhysics without having to make a CCPhysicsNode, but at the same time it's still possible to create extra CCPhysicsNode instances. Physics Grabbing. (Easy)

ChipmunkMultiGrab is a pretty handy utility class. It allows you to implement multi-touch physics interaction fairly easily. There is a push and a pull mode to it, and they are mutually inclusive. The pull mode is the more obvious of the two. When you touch a shape it will add a joint to it and let you drag it around the screen. Push mode happens when you touch the screen where there isn't a shape. Instead it adds one for your finger so you can nudge other shapes around. So basically it implements the two ways that you would interact with objects laying on a table using your finger. It's all properly force limited and works using constraints so it's fairly hard to break it.

I think this might be as easy as CCPhysicsGrabNode subclass, overriding hitTestWithWorldPos: and implementing the CCResponder methods to pass the touches on to ChipmunkMultiGrab. Kinematic Bodies. (easy)

The code for this already exists, and is only commented out of the public API because there was a lot of confusion about what kinematic bodies were. Interpolation. (medium)

Currently there are no options for interpolating rigid body positions for the non-fixed update loop. It's probable that people are going to run into issues with the motion of their physics stuttering even if the framerate is smooth if they start playing around with fixed update settings. Avoiding this would be a good thing.

This isn't too hard to implement, though making it work along with actions makes it much harder. Joints. (indeterminate)

CCPhysics only supports a basic set of joints. I was conservative about adding more joint types because they are a real pain to support and document all of the different variations that are already in Chipmunk. I implemented the four most common joints from Chipmunk.

I have some potentially big ideas about configurable joints in Chipmunk that might change how I want to go forward with them in CCPhysics. Projectile Bodies. (medium)

A body with a ray query instead of a shape. This allows for very cheap swept collision bullets without the expense of full swept collisions. I haven't figured out a sensible way for this to fit in with the regular collision delegates though. Actions. (hard)

There has already been a lot of discussion about this here: #381https://github.com/cocos2d/cocos2d-iphone/issues/381. Short summary is that actions and physics integrate together in Cocos as poorly as the equivalent features in SpriteKit or Unity. There is a lot of room for improvement.

— Reply to this email directly or view it on GitHubhttps://github.com/cocos2d/cocos2d-iphone/issues/479 .

slembcke commented 10 years ago

Configurable physics debug colors? https://github.com/cocos2d/cocos2d-iphone/issues/470

The debug drawing should also be updated to render the rounded corners of polygons.