[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Tue Jan 27, 2015 1:50 pm

Newton's cradle in 3 events ;) The key is to use the circle collision shape, max elasticity & zero friction.
You do not have the required permissions to view the files attached to this post.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Tue Jan 27, 2015 2:04 pm

Still not true physics though as i am pretty sure real steel balls dont have any elasticity. :)

Edit: Corrected by R0J0hound below :). I learn something new everyday.
Last edited by spongehammer on Tue Jan 27, 2015 9:20 pm, edited 1 time in total.
B
50
S
16
G
9
Posts: 1,098
Reputation: 11,237

Post » Tue Jan 27, 2015 2:10 pm

@mattb, sorry.. it doesn't work at all the way a newtons cradle should...There are all types of things happening with collisions in your example...The first thing is that I don't think using drag-drop works well with chipmunk physics to drag chipmunk objects over other...
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Tue Jan 27, 2015 2:36 pm

It has always been stated that the physics behavior shouldn't be mixed with the other behaviors, as unforeseen things can happen.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
87
Posts: 5,490
Reputation: 60,266

Post » Tue Jan 27, 2015 4:38 pm

Ok here's another version without the drag-drop, & just an impulse to start things off. There's still some movement of the inner balls (which gets worse if you enable the infinity sleep time action) but it's pretty close to the expected result i think, & probably as good as the physics will allow.
You do not have the required permissions to view the files attached to this post.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Tue Jan 27, 2015 6:24 pm

@Prominent thanks for the report. I'll be looking into it.

@spongehammer
You can already get the impulse applied to a joint so yes you can make something like that.

@kmsravindra
#1 Physics libraries are only a approximation, so energy isn't always conserved. You can increase the "global settings"->iterations to make it more accurate. You can also make the fixed timestep smaller to make collisions more accurate as well.
#2 Toggling immovable isn't the best way to drag objects around. The switch discards any contact points and isn't very physically correct. A better way is to attach a joint to an object that is moved directly. See bottom of post.
#3 If it causes a js error then it's a bug. I'll look into it.

@spongehammer
It's correct, elasticity in physics is how a collision reacts, not how rubbery it is. An elasticity of 1 should mean that no energy is lost in a collision, which is pretty much how ball bearings act when they collide.


Attached is a physics way to drag objects around. When you click on an object you create a joint to a no collision, immovable sprite that is moved around by the mouse. Then when the mouse is released the joint is removed.

Also the joints in the capx are set to break if you're too rough.
You do not have the required permissions to view the files attached to this post.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Tue Jan 27, 2015 7:16 pm

if it helps, this is the error I get about the angle thing..
Error: Assertion failed: Internal Error: Attempting to set body's angle to NaN
at assert (http://localhost:50000/rojoChipmunkBeta ... or.js:51:9)
at Body.setAngleInternal (http://localhost:50000/rojoChipmunkBeta ... .js:1725:2)
at Body.position_func (http://localhost:50000/rojoChipmunkBeta ... .js:1768:7)
at Space.step (http://localhost:50000/rojoChipmunkBeta ... js:4998:14)
at behinstProto.tick (http://localhost:50000/rojoChipmunkBeta ... js:6983:17)
at Runtime.logic (http://localhost:50000/preview.js:2346:29)
at Runtime.tick (http://localhost:50000/preview.js:2066:8)
at tickFunc (http://localhost:50000/preview.js:629:38)
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Tue Jan 27, 2015 8:48 pm

@R0J0hound - a couple of things:

1. Are the single contact points of the green boxes below an expected behavior?

coll_pairs.png

coll_pairs.capx


2. Could you give a quick explanation or example of how to use the hexadecimal numbers for collision layers?

Thanks :)
You do not have the required permissions to view the files attached to this post.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Tue Jan 27, 2015 10:24 pm

Also been getting this error.. not sure what is causing it though.. edit:seems to occur when a line collides in two places at the same time...

Error: Assertion failed: Cannot remove a shape that was not added to the space. (Removed twice maybe?)
at assert (http://localhost:50000/rojoChipmunkBeta ... or.js:51:9)
at Space.removeShape (http://localhost:50000/rojoChipmunkBeta ... .js:3889:3)
at behinstProto.updateShape (http://localhost:50000/rojoChipmunkBeta ... js:6642:16)
at behinstProto.changeShapeCheck (http://localhost:50000/rojoChipmunkBeta ... js:6956:10)
at behinstProto.getBody2 (http://localhost:50000/rojoChipmunkBeta ... .js:7598:8)
at Acts.addPivotJoint (http://localhost:50000/rojoChipmunkBeta ... js:7643:20)
at Action.run_object (http://localhost:50000/eveng.js:1843:10)
at EventBlock.run_actions_and_subevents (http://localhost:50000/eveng.js:929:38)
at EventBlock.run (http://localhost:50000/eveng.js:886:9)
at EventBlock.run_subevents (http://localhost:50000/eveng.js:994:11)
at EventBlock.run_actions_and_subevents (http://localhost:50000/eveng.js:933:8)
at EventBlock.run (http://localhost:50000/eveng.js:886:9)

EDIT: seems to occur when a line collides in two places at the same time...
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Tue Jan 27, 2015 11:12 pm

@R0J0hound , also, I'm noticing that if a line is created overlapping another object so that it extends across two sides, it'll position the line twice the depth rather than just once- this causes the line to be pushed out way too far. I'm guessing that it somehow positions it for each collision point, which is why it pushes it out too far.

edit: actually.. to be more accurate, I tried to push it out via collision depth * normal.. but it seems to be pushing it too far out when it extends across to sides. If it extend across one side it pushes out fine.

edit2: actually maybe it's fine. Since I move it to the collision point, and then push it, seems like I don't need to push it out. For some reason though, sometimes the collision point is inside objects, and I'm not sure how to get the collision point on the edge of the object when this happens..
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests