[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Sun Feb 08, 2015 5:59 pm

has anyone implement a platformer movement with this?
is it possible to set the player's velocity manually without it going through walls or pushing heavier objects?

a kinematic body perhaps would be best for this job i dont know if that possible in this plugin
or maybe pinning the player to a dummy with a pin joint
B
3
Posts: 9
Reputation: 193

Post » Sun Feb 08, 2015 6:15 pm

@bla6546 , this is a simple example of something I put together. I didn't really spend too much time on a platform movement yet, but you can see the basics already.
Image
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Sun Feb 08, 2015 7:44 pm

Anybody tried this behavior in Crosswalk? Using Box2D I loose 30 FPS :(
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Sun Feb 08, 2015 8:17 pm

@TheWwrm, I tried this a couple of weeks ago on my laptop and its performance was almost identical to box2d web (and asm.js - Ashley and I disagree on the latter's performance hike).
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,255
Reputation: 46,484

Post » Mon Feb 09, 2015 6:01 am

@Prominent
The slowdown is from a memory leak somewhere that's preventing stuff from being garbage collected, but I haven't had much luck identifying where, although hearing that restarting the layout speeds it up is helpful to know.

Negating gravity was the main purpose for pre-step. There may be other uses, since the chipmunk library has it too.

Joints in the chipmunk library are velocity based, which means they change the connected bodies' velocity so that the joints match up. The pin joint in your capx from best I can tell does a better job than just setting the object's position. Without the pin joint you're just transporting a free-falling object, so the y velocity would always be increasing and make it swing more. Maybe you could pin to an immovable object and move that if you want the pin point to move.

With physics libraries it's generally better to constrain objects with joints than setting position and velocities. At least from what I've seen.

@bla6546
It already has angular velocity.
"surface velocity" may indeed be useful, I'll put it on the todo.

A kinematic body is just a body not affected by gravity, correct?
For that you just undo the gravity in a "pre-step" condition like so as I recall:

Pre-step:
Apply force rect(0, -Self.Chipmunk.mass * Self.Chipmunk.gravityY)
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Mon Feb 09, 2015 6:40 am

This seems quite nice, and complete. Thank you @R0j0hound.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Mon Feb 09, 2015 7:28 pm

according to the chipmunk's manual:

"Kinematic bodies are bodies that are controlled from your code instead of inside the physics engine.
They arent affected by gravity and they have an infinite amount of mass so they don’t react to collisions or forces with other bodies.
Kinematic bodies are controlled by setting their velocity, which will cause them to move.
Good examples of kinematic bodies might include things like moving platforms.
Objects that are touching or jointed to a kinematic body are never allowed to fall asleep."

also i havent figured out how to make a player's movement with this, apparently its 2 bodies attached with a pivot joint and a simple motor joint (with a rate of 0) then dynamically adjust the maxForce to the desired friction, i haven't tried it though, i think this should be in their manual since it is such a common thing to attemp
B
3
Posts: 9
Reputation: 193

Post » Mon Feb 09, 2015 7:55 pm

OFF TOPIC
newt wrote:Hmm, R0J0's been quite lately.
He must either be:
A. Teaching Chuck Norris how to be a computer ninja, or
B. Making a paradigm changing plug.



loller .... btw u know u have more badges then tom and ashley?:)) funny ....


On topic looks great :X let me try this :D
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Thu Feb 12, 2015 11:47 pm

If no one has already posted benchmarks then here we go:

These were made using a win7 i5 laptop.

The test, Box containing small bouncing balls with 100% elasticity... I continued to add balls until the cpu usage fluctuated to greater than 85%

Box2dWeb: 600
AMS.JS: 850
Chipmunk: 1400

Something to note here which is very important. AMS.JS Keeps low cpu usage and then once you cross a object count it sky rockets to 90-100% . Box2d is much more linear in its object count to cpu usage. Chipmunk starts to use more cpu as the balls settle (which they shouldn't be doing). The settling becomes more pronounced as the object count increases.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,163

Post » Fri Feb 13, 2015 12:47 pm

ruskul wrote:Chipmunk starts to use more cpu as the balls settle (which they shouldn't be doing). The settling becomes more pronounced as the object count increases.


Chipmunk's default settings for putting an object to sleep seem too aggressive. I sometimes get floating physics sprites when an object underneath is knocked away, worse for circle collision shapes since their contact area is lower.

A fix is to adjust idle speed threshold and/or sleep time threshold. Maybe try an idle speed threshold of 0.5s at first. If things are still settling too soon then lower it, or try a sleep time threshold of 2s.

You can disable sleeping altogether by setting sleep time threshold to 'Infinity'.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests