[BEHAVIOR] Chipmunk Physics

From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • R0J0hound Is there a way to use multiple collision groups with one object? Let's say I want that object A does not collide with objects B and C but collide width D and F. In the chipmunk doc I found that it's possible to set multiple collision groups on one object, but in C2 plugin I can't find the way to achieve that.

  • xoros - you want the Collision Layers property for the behavior to do that. It takes 8 hexadecimal digits to give you 32 possible layers, but I just use 0's & 1's, giving me 8 collision layers.

    In your example, this is how I'd set up collision layers for each object:

    10000000 - A

    01000000 - B

    01000000 - C

    11000000 - D

    11000000 - F

    So you can see each column in the matrix is a layer, & any two objects in a column sharing a 1 will collide.

    Here's a more complex example where A doesn't collide with B & C, but collides with D & F.

    B doesn't collide with C or D, but does with F.

    C collides with D, but not B or F.

    D collides with A, F & C but not B.

    F collides with A, B & D but not C.

    10000000 - A

    01000000 - B

    00100000 - C

    10100000 - D

    11000000 - F

    Then you could extend this by giving all instances of a particular object a Collision Group number (which is just a single integer). Objects with the same non-zero group number won't collide.

    This is handy if say object F is physics debris & doesn't need to collide with other F's for performance reasons.

  • mattb thanks for explantion

  • Had a go at making some dynamic smoke for a stealth game, the idea being that it can block LOS or laser raycasts & triggers smoke detectors...

    https://dl.dropboxusercontent.com/u/523 ... _test.capx

  • >

    > It's not using the object's origin, it's just using the center of the object regardless of where the origin is. It was an oversight to not take into account the center of a polygon shape. I'll be taking a look into it.

    >

    Dont want to seem pushy but how is this coming along.

    Thanks

    R0J0hound , & spongehammer

    I was looking into that, but I'm not sure what would be the best way? Perhaps directly addressing to the center of the object as the first imagepoint of the sprite?

    I believe the part of the code that should be edited is around lines 183->

    cp.centroidForPoly = function(verts)
    {
    	var sum = 0;
    	var vsum = new Vect(0,0);
    	
    	for(var i=0, len=verts.length; i<len; i+=2){
    		var v1 = new Vect(verts[i], verts[i+1]);
    		var v2 = new Vect(verts[(i+2)%len], verts[(i+3)%len]);
    		var cross = vcross(v1, v2);
    		
    		sum += cross;
    		vsum = vadd(vsum, vmult(vadd(v1, v2), cross));
    	}
    	
    	return vmult(vsum, 1/(3*sum));
    };
    
    cp.recenterPoly = function(verts)
    {
    	var centroid = cp.centroidForPoly(verts);
    	
    	for(var i=0; i<verts.length; i+=2){
    		verts[i] -= centroid.x;
    		verts[i+1] -= centroid.y;
    	}
    };[/code:2noityua]
    
    also lines 1532->
    [code:2noityua]
    /// Position of the rigid body's center of gravity.
    	this.p = new Vect(0,0);
    	/// Velocity of the rigid body's center of gravity.
    	this.vx = this.vy = 0;
    	/// Force acting on the rigid body's center of gravity.
    	this.f = new Vect(0,0);[/code:2noityua]
    
    However, the problem with the solution is that how objects without imagepoint such as tilemaps would have their center calculated correctly with the introduction of the secondary imagepoint as center of mass feature? Did you have any breakthrough idea on this R0J0?
    
    p.s. @mattb that's nicely done steam effect
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Sometimes objects with chipmunk physics do not register standard overlapping/ on collision events. Actually they do not register most of the time. They tend to register standard collision only if collision impact is very strong (was moving at high speed). Is it a bug or a feature?

  • xoros

    It independent of C2's collision detection, so it doesn't trigger a collision event. The built-in physics does, but for this plugin it's better to use the collision triggers it has since you can get more info about the collision.

    striimix

    It's not exactly a simple change. Right now a vector is calculated from the object's center to the origin, and that is used to update the sprite's position from the physics position, and vise versa. I just need to update the math to use the COM instead of the center, which is tricky enough to require a re-think of a lot of the code. I need to handle moving the com when resizing and changing animation frames and collision shapes while at the same time keeping the object stationary.

    Calculating the COM isn't an issue as Chipmunk provides functions to do that for all of it's shapes. The tilemap would be a special case which would be an average of the tile's COM. But I probable won't do that since tilemaps can't rotate and are usually static so it would be a needless calculation.

  • Thanks for the clarification R0J0hound

    it indeed seems very complicated change - and good point about the tilemaps! Just after posting here, I thought about the tilemap case being unnecessary (it must be these late working hours that made me not think straight). After few "quick" tests with image points, I decided better to not edit the physics engine but go with "fake it until you make it" approach instead. Basically "tricking" the system to have the center correctly set by having size adjusted invisible sprite with chipmunk physics and the real sprite pinned onto the chipmunk object

  • I added a pivot joint between two object, but when I set, make changes to the ang velocity the joint origin don't keep up with the changes. Same happens when it hits something.

    Is this some limitation of chipmunk?

  • Giganten

    It's generally better to use forces and torques to change the motion of the objects. Changing the velocities directly won't give very realistic results although you can increase the iterations setting to make it do a better job of keeping up.

  • Thank you R0J0hound, learned something new today.

  • incase anyone is wondrering, you cant get good collision using this with default 8 dir movement plugin...

  • gogobotz

    When physics is concerned (this or the official physics behavior) it doesn't mix well with other movement behaviors. So to to have 8 direction with physics you'd need to do it all with physics.

  • gogobotz

    When physics is concerned (this or the official physics behavior) it doesn't mix well with other movement behaviors. So to to have 8 direction with physics you'd need to do it all with physics.

    thanks alot with this info i was able to achieve perfect collisions but now i have a question that has been bugging me

    i am trying to keep objects at specific angles when they approach within angles. (like limits) and am unsure the best way? should i apply torque with + or - a number or use built in C2 set angle? I want them to rotate towards a position on a pivot when approaching a certain angle.

  • I noticed there is the option to disable the chipmunk behavior on an object.

    I tried doing this to an object that has a joint with another object, and noticed that the other object still is affected by the joint attached to the disabled object.

    Is there a way to disable/enable the joint as well so I don't have to recreate them everytime I want to disable/enable the behavior?

    R0J0hound , maybe an action to disable/enable a joint given its' tagname?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)