Physics weirdness with custom collision + physics questions

Post your own tutorials, guides and demos.

Post » Thu Dec 17, 2009 7:22 am

Noticed something weird going on with custom collisions and physics

Download:Example Really simple example cap to show the problem.

The custom collision is setup correctly around the object following the mouse, but when it's run, the collision shape is somewhere above the object. The hotspot has to be where it is (think of it like a paddle in a pinball game, rotating at that point, even though it doesn't in this example).

Is this a known issue or did I just set something up wrong?


Also three questions

1 ) How do you increase the accuracy of the physics. I've seen other people's examples and objects bounce and collide perfectly, even with tons of physics objects all interacting at once, without any of them passing through each other or acting weirdly, yet whenever I've tried to do the same, objects just snap and bug out much of the time and the physics come across as incredibly flakey for me. I've set the World Solver and World Friction to their highest setting and seen no improvement. I've used objects that aren't any different in mass or size (I read about that issue on the wiki and made sure to check it wasn't that). I just can't seem to make them behave like other people can, even when I attempt to mimic what they did in their exe's. Does it need something to do with timedelta? I know it's not my machine, as like I say, others have worked fine for me.

2 ) Are there issues with physics objects and mouse control? Again, seems flakey for me when I use it, yet I've seen it in others creations that appear to work and behave just fine (one had leaves being pulled about with a mouse (which is moved about quickly) and lots of physics going on and looked flawless). So I'm clearly doing something wrong. :)

3 ) Tiny request, not a big deal, more curiosity really. Will there eventually be an option with creating custom collisions to drag the points around after creating them, as opposed to the current method of having to delete them all to go back to one you want to change.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Thu Dec 17, 2009 9:50 am

As far as I know the hotspot for any physics object needs to be centered in order for the collision to work properly. If I remember correctly this has something to do with the way Box2D works.

If you need the hotspot at the edge of the flipper for whatever reason then make your sprite like so:



Then when you draw your custom collision mask in the layout, just place your points around the colored area like normal.


[quote="Lost my Keys":8g5bdfig]1 ) How do you increase the accuracy of the physics.[/quote:8g5bdfig]

It's hard to say without a .cap to look at to see what's wrong.

[quote="Lost my Keys":8g5bdfig]2 ) Are there issues with physics objects and mouse control? Again, seems flakey for me when I use it[/quote:8g5bdfig]

Yes. If you manually move a physics object with the mouse or a behavior or by updating it's coordinates in any way except with physics itself, then you will get weird collisions. Also, when you manually move the flipper against the ball with the mouse, the flipper has no force, so it's not actually "hitting" the ball. You're just intersecting the flipper and the ball. The ball and the flipper are trying to push out of each other, but the mouse behavior is overriding it's position.

Here's a method for moving physics object around with the mouse that may suit your needs:

http://dl.dropbox.com/u/529356/dragandtoss.cap

It's got a little bit of lag behind the mouse but it works pretty well.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Dec 17, 2009 12:17 pm

[quote="deadeye":2b4pdis3]As far as I know the hotspot for any physics object needs to be centered in order for the collision to work properly. If I remember correctly this has something to do with the way Box2D works.

If you need the hotspot at the edge of the flipper for whatever reason then make your sprite like so:



Then when you draw your custom collision mask in the layout, just place your points around the colored area like normal.[/quote:2b4pdis3]

Ahhhh! Ok that makes complete sense now, I see where I was going wrong (didn't think the hotspot location would matter, but yep, that's the problem right there). Neat way to fix it too, didn't think of doing it that way either. Awesome! :D

[quote="deadeye":2b4pdis3]
[quote="Lost my Keys":2b4pdis3]1 ) How do you increase the accuracy of the physics.[/quote:2b4pdis3]

It's hard to say without a .cap to look at to see what's wrong.[/quote:2b4pdis3]

No need, you practically answered, fixed and showed a better way for that question below (it's cause I often test stuff using the mouse behavior for speeds sake, and that's where I was screwing up when it came to physics). A classic case of the error being between the computer and the chair. :D

[quote="deadeye":2b4pdis3]
[quote="Lost my Keys":2b4pdis3]2 ) Are there issues with physics objects and mouse control? Again, seems flakey for me when I use it[/quote:2b4pdis3]

Yes. If you manually move a physics object with the mouse or a behavior or by updating it's coordinates in any way except with physics itself, then you will get weird collisions. Also, when you manually move the flipper against the ball with the mouse, the flipper has no force, so it's not actually "hitting" the ball. You're just intersecting the flipper and the ball. The ball and the flipper are trying to push out of each other, but the mouse behavior is overriding it's position.

Here's a method for moving physics object around with the mouse that may suit your needs:

http://dl.dropbox.com/u/529356/dragandtoss.cap

It's got a little bit of lag behind the mouse but it works pretty well.[/quote:2b4pdis3]

*sigh* So simple and yet so perfect. :) It works fine, and comparing it to any testing I've done, the only difference is it's not using the mouse behavior, and from what you say above, that's clearly where I've been going wrong and the reason it's not been working well for me. I did wonder briefly if 'lock' was a special kind of private variable, then realized what was going on. I need to practice more with private variables I think too. :)

Thank you so much!!! :)
B
3
S
2
G
3
Posts: 628
Reputation: 2,531


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 3 guests