[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Wed Jul 15, 2015 7:38 am

spongehammer wrote:
R0J0hound wrote:@DatapawWolf
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 , @DatapawWolf & @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->
Code: Select all
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;
   }
};


also lines 1532->
Code: Select all
/// 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);


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
B
14
S
3
G
1
Posts: 77
Reputation: 1,035

Post » Wed Jul 15, 2015 10:31 am

@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?
B
45
S
11
G
4
Posts: 515
Reputation: 7,389

Post » Wed Jul 15, 2015 7:42 pm

@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.
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Wed Jul 15, 2015 10:36 pm

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 ;)
B
14
S
3
G
1
Posts: 77
Reputation: 1,035

Post » Thu Aug 13, 2015 5:12 pm

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?
B
15
S
3
G
3
Posts: 93
Reputation: 1,466

Post » Thu Aug 13, 2015 7:24 pm

@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.
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Thu Aug 13, 2015 8:08 pm

Thank you @R0J0hound, learned something new today.
B
15
S
3
G
3
Posts: 93
Reputation: 1,466

Post » Sat Aug 22, 2015 12:08 am

incase anyone is wondrering, you cant get good collision using this with default 8 dir movement plugin...
B
2
Posts: 8
Reputation: 168

Post » Sat Aug 22, 2015 7:47 am

@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.
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Sat Aug 22, 2015 3:42 pm

R0J0hound wrote:@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.
B
2
Posts: 8
Reputation: 168

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest