Box2D Forums

It is currently Thu May 23, 2013 2:02 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Mar 26, 2012 4:35 pm 
Offline

Joined: Thu Mar 22, 2012 2:45 am
Posts: 6
Hi everyone,

I'm making an iPad game where you shoot disks with a rubber band.
I simulate the throwing of disks via the rubber band by giving them an impulse with ApplyLinearImpulse once you draw the disk on the rubber band and release it.

I want the impulse to be stronger if you drew the rubber band further, so I'm calculating the length in pixels of how much the rubber band was drawn and apply a greater impulse accordingly.

Basically, I use a factor by which I multiply the pixels to get the actual impulse vector (the impulse vector is always up so has x = 0 and y = something).
Note that this is a game from above, so I'm using linear damping to simulate the friction fo the disks on the board (set to 2.5).

Once you release the disk it goes to the other side of the board, reaches a position where I reverse its direction speed and stops gradually because of the damping.

The thing is, even though I check the factor, and see that it is 2000 for small rubber band draws and 10000 for large ones, the larger draw still gets the disc less far than the small one.
What can be causing this?
I'm completely sure this is not related to my logic, but to the engine behaviour, since I debugged and saw the values of the impulse...

Can this be because of the high damping value?

The disks have friction of 2.0, density of 7.0, restitution of 0.5, the damping is 2.5 and the PTM ratio is 32.
I'm using a velocity iteration of 6 and a position iteration of 1, and running the engine with a variable time step.

Thanks!
Idan


Top
 Profile  
 
PostPosted: Mon Mar 26, 2012 10:08 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
You might be hitting the velocity cap. Try adjusting b2_maxTranslation.


Top
 Profile  
 
PostPosted: Tue Mar 27, 2012 3:15 am 
Offline

Joined: Thu Mar 22, 2012 2:45 am
Posts: 6
That seems right, however I changed it from 2.0f to even 100000.0f and still there is a strange effect in which a 2000 velocity vector shoots the disk farther than a 10000 one...
Maybe there is another constant I should update?


Top
 Profile  
 
PostPosted: Tue Mar 27, 2012 5:11 am 
Offline

Joined: Thu Mar 22, 2012 2:45 am
Posts: 6
Sorry I was wrong, it does work. Since the constant is a define I needed to clean the project first.

Thanks for the help!
Idan


Top
 Profile  
 
PostPosted: Tue Mar 27, 2012 6:34 am 
Offline

Joined: Thu Mar 22, 2012 2:45 am
Posts: 6
I changed the constant from 2.0f to 2500.0f.
What problems can arise from that?
Since I am getting strange reactions where disks fly all over passing through walls once in a while...


Top
 Profile  
 
PostPosted: Tue Mar 27, 2012 9:14 pm 
Online

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
The default setting says that a body can only move a maximum of 2 units per time step. The optimal size for 'bodies' (well... fixtures) is around 1 unit, so the default velocity cap would prevent a body from moving too much more than its own size in one step. Although not critical, these values are chosen to work well together. If you set the velocity cap much higher as you have done, the body can move so fast that it leaves huge empty spaces between each position from frame to frame, and has less chance of detecting a collision with something else.

But 'bullet' bodies should still detect a collision even in situations like that. Have you tried setting the disk bodies as 'bullet' bodies?

Generally my recommendation would be to leave the values in b2Settings as they are, and get to the real root of the problem which I am guessing could be the PTM ratio... are you keeping the most common size of your bodies around 1 unit?


Top
 Profile  
 
PostPosted: Wed Jun 13, 2012 3:02 am 
Offline

Joined: Wed Jun 13, 2012 2:59 am
Posts: 5
I have the same problem. I use Java with box2d, I can't find how to change maxTranslation. How else could I resolve this problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group