[BEHAVIOR] Chipmunk Physics

Post your completed addons to share with the community

Post » Fri Mar 06, 2015 7:52 am

Thanks @R0j0hound, however, I'd prefer not post that capx, since it's an almost finished game project. I'm trying to replicate the problem on a fresh capx, but so far no luck... perhaps some other part of my code is causing it, so I will have to look deeper into it and update here in case I discover a reliable way to replicate it.
B
14
S
3
G
1
Posts: 77
Reputation: 1,035

Post » Sun Mar 08, 2015 12:43 pm

R0J0hound wrote:You shouldn't need to use dt anywhere.


I didn't realize this, & I see the same is also true of c2's native physics which defaults to the same fixed timestep. Time to multiply all my force vars by 1/60... :D
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Sun Mar 08, 2015 9:12 pm

I'm making a game that uses chipmunk's slide constraint for swinging rope segments, adjusting the rope length by setting the joint's max distance value (which is a hacky approach i know). It all works perfectly apart from one thing: if you run the attached capx & press the up arrow key to shorten the rope, you'll see some wild collision as you clip a corner.

Now if you set Prevent Rotation on the red sprite this doesn't happen - you just get dragged up with a bit of intersection, but no crazy swinging.

Can anyone think of a workaround where I don't turn off rotations?

(note: the ropes in my game never intersect with scenery because there's a wrapping system; this is just a quick example)
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 » Mon Mar 09, 2015 3:43 am

@mattb
One idea that may work is use a force on the object toward the base of the rope and just set the length as it gets closer. That may be more true to life where a force would be used to pull the rope in. You could also instead set the velocity of the object parallel to the rope as well, which would make the rope retract at a constant rate. For the latter you'll need this formula to get velocity along an angle:

velocity at angle = vx*cos(ang) + vy*sin(ang)

So given:
ang= angle of rope
and
rope_vel

We can set the velocity so the perpendicular velocity stays the same and the velocity along the rope is whatever value we want.

perp_vel= vx*cos(ang+90) + vy*sin(ang+90)

vx=rope_vel*cos(ang) + perp_vel*cos(ang+90)
vy=rope_vel*sin(ang) + perp_vel*sin(ang+90)

Then as with the first idea only set the rope length as the object moves closer.

Edit:
A third idea would be to set the maximum force of the joint so that the collision isn't as radical.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Mon Mar 09, 2015 1:53 pm

I think your idea of setting velocities separated into components that are along or perpendicular to the rope is the approach i should have taken from the start. Although I did try something like this & didn't like how the player's angle wasn't affected.

Retraction/extension forces I found too hard to tweak - they always gave too much acceleration, & the damping needed to compensate interferred with the overall feel of swinging (probably my bad coding though).

Maximum joint force seems to be just the hacky fix I was after though, thanks :)

By the way here's what I've been making: https://dl.dropboxusercontent.com/u/523 ... index.html
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Mon Mar 09, 2015 7:08 pm

@R0J0hound can i use it for altering the gravity to be towards Z axe? like in 3d? where u have x (lft right) y (up down) but towards Z(altitude?) thanks need to know how to achieve it with this plugin, and if its even possible, i need it to be able to use with Q3Dplugin axes, like a 3d gravity ability.

Edited

Bummer ... Thanks :) i tested it for pool game , its kinda good, but still sometimes balls passes through each other not sure if its the collision check the fault or the images being to small.. good plugin :) keep up the good work.
Last edited by gamecorpstudio on Mon Mar 09, 2015 7:37 pm, edited 1 time in total.
B
75
S
22
G
68
Posts: 1,334
Reputation: 43,265

Post » Mon Mar 09, 2015 7:10 pm

@gamecorpstudio
The plugin only does 2d physics so using z is not possible with the plugin.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Sat Mar 14, 2015 10:12 pm

@R0J0hound - any idea what's happening here? The reason I'm trying this is to see if I can redo my rope wrapping system to use segment collision shapes & contact points. The contact points work perfectly, but I can't get the rope's position post collision.
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 » Sat Mar 14, 2015 10:21 pm

Nevermind, got it to work with a pre-step event...


***EDIT - a better way to get the colliding object's position post collision is by using ObjectName.Chipmunk.local2worldXY, which lets you set an offset from the object's CoM, so in this case it would be Rope.Chipmunk.local2worldXY(-Rope.width/2,0) to find the start of the rope.
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 » Thu Mar 19, 2015 10:13 am

Hi R0J0hound,

Firstly I just want to thank you for this excellent behavior, it pretty much fixes all the things that I was finding frustrating with the Box2D behavior.

One thing I cannot seem to find though, and I`m sure I must be missing something obvious, is the ability to 'weld' objects together. Essentially I want to create complex shaped objects by welding two or more objects together, there is no movement between the two objects being welded.

A good example (using Chipmunk) would be the Motorbike`s and tank`s bodies in this video:
https://www.youtube.com/watch?v=vEZhPpSCAMw&t=88

Any help would be much appreciated.
RR
B
16
S
4
Posts: 35
Reputation: 2,393

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests