[BEHAVIOR] Chipmunk Physics

» Tue Dec 30, 2014 1:23 am

@Prominent
The relative positions for the joints is relative as if the object was unrotated. so if the object's angle was 90 degrees a relative offset of rect(10, 0) would be (sprite.x, sprite.y+90). But also keep in mind as the sprite rotates the point will adjust. I wonder if I should make the offset relative to the sprite's current angle. It might be a bit more intuitive.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

» Tue Dec 30, 2014 2:43 am

@R0J0hound , hmm.. I think that is confusing. Here's what I'm trying to do:
simpleWarp.capx

Basically join objects together if their imagepoints are close enough..
If the joints are being added as if they're at an angle of 0 instead of the current angle, then I'm not sure how to do that easily. I'd have to somehow calculate where the imagepointX would be based upon how many degrees off from zero the object is. Seems like a lot of extra calculations.

Edit: btw, the capx shows that it's not working how I'd expect it to. If you could help me figure out how to make it work, that would be cool.
You do not have the required permissions to view the files attached to this post.
B
51
S
24
G
68
Posts: 1,182
Reputation: 40,340

» Tue Dec 30, 2014 5:04 am

I think a pivot joint would work better than a pin. You can try the "add pivot joint at xy" action with parameters:
Family2.uid
Family1.ImagePointX(loopindex("points"))
Family1.ImagePointY(loopindex("points"))

Every other joint uses relative locations but that one uses a layout location. I think I'll add a "layout2relative" expression so we can use layout locations for the other joints if needed.

Also according to the chipmunk forums a good way to join objects together is with two joints, a pivot and a gear joint (with a 1.0 ratio). I modified your capx to do that, also for the gear joint it needs a phase of Family2.Angle-Family1.Angle to keep the angle difference of the objects.
You do not have the required permissions to view the files attached to this post.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

» Tue Dec 30, 2014 6:44 am

Update #8
+Added world2local and local2world expressions to convert coordinates.
+Fixed a few typos in the ACEs

@Prominent
Here's another tweak of your capx using the new conversion expressions. There still is some joint fighting when there is more than 1 joint between two objects that can cause the objects to move on their own.
You do not have the required permissions to view the files attached to this post.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

» Tue Dec 30, 2014 7:37 am

@R0J0hound , that looks much improved- can actually see them connecting correctly. Yea, the joint fighting is pretty bad, hope that can be solved. Is that something you'd need to address with how chipmunk is implemented?

edit: actually.. I tried moving all the imagepoints outwards 1 pixel on each sprite so that the polygons won't touch when attached, and it got rid of the fighting syndrome. Works perfectly like this. There's a visible gap between objects, but that can be solved by moving the polygon points inwards instead of moving the imagepoints I think..
Do you know why it would act crazy if the polygons touch? I'm wondering if that is something that needs solving even though this approach works.

Also, it's cool seeing your changes to the events, I saw some new ways of doing things that I hadn't seen before which will make my life easier.
B
51
S
24
G
68
Posts: 1,182
Reputation: 40,340

» Tue Dec 30, 2014 5:30 pm

@Prominent
It acts crazy because the joints are pulling the blocks into contact which in turn try to push out of each other. Floating point numbers introduce a tiny bit of error so sometimes the objects won't be in contact but will overlap a little, which causes the fighting. Offsetting the points or polygon is a good solution. I don't think there's anything I can do in the behavior code, it's just how the physics works.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

» Tue Dec 30, 2014 6:05 pm

@R0J0hound , okay, makes sense. I'll continue experimenting with your behavior.
Thanks for the help, this is a great behavior!
B
51
S
24
G
68
Posts: 1,182
Reputation: 40,340

» Tue Dec 30, 2014 7:38 pm

Here's a test that plays a sound when object's collide. The volume varies by how much Kinetic energy is in the hit. You can fiddle with the equation that maps to volume to adjust it. In a similar way I added puffs of dust that spawn at the contacts.
You do not have the required permissions to view the files attached to this post.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

» Wed Dec 31, 2014 6:59 pm

Updated #9:
Removed beta from name since it's pretty much feature complete.

Edit:
Could this topic be moved to completed addons?

Also a collision layers test:
You do not have the required permissions to view the files attached to this post.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

» Thu Jan 01, 2015 9:52 am

This is a great plugin! I'll definitively use it:D
B
34
S
15
G
6
Posts: 245
Reputation: 4,374

PreviousNext