Extending pad?

Official forum for the Chipmunk2D Physics Library.
Post Reply
Hexasoft
Posts: 7
Joined: Wed May 04, 2016 10:51 am
Contact:

Extending pad?

Post by Hexasoft »

Hello,
I used Chipmunk some years ago and started again to use it for a test game for a multitouch table I'm creating.

In this game (a kind of pong) I would like players to manipulate a pad (or racket?) which can be extended to a limited size.
So I planed to create 2 bodies - on for each side of the pad, linked together by a string, and moved by a link (spring) to other bodies that are controlled by player fingers.
Of course I also need a box between the 2 sides for collisions (let say it would looks like: (====) ).

But I read that changing a shape is unsafe! Can you help me? Should I use these unsafe functions? Can you see an other way to do what I want to do?

Thanks in advance!

Regards,
--
Hexasoft
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Extending pad?

Post by slembcke »

It's "unsafe" because there is no way for the collision response to take the movement of the surface into account. When you change a shape, it doesn't move from point to point, it instantly changes. So instead of the collision response knowing that this surface hit this other surface moving at this speed, it will find that the surfaces are overlapping with no history or motion information. The way that is handled is to softly push the surfaces apart which can make collisions seem soft and mushy. Like colliding with foam or a sponge.

Now with all of that in mind, those mushy collisions only happen where the surface changes. The flat parts of your paddles with act fine. The ends are a little bit more complicated. If the paddle as a whole is moving at 5 units per second, and the paddle end is stretching outwards at 2 units per second, then you'd want the collision to think the surface is moving at 7 units per second. Since the collision response doesn't know about the stretching, it will think it's happening at 5 units per second. In most cases, this might not be enough for the player to even notice. Chipmunk also has a feature called surface velocity that allows you to handle this, but it's fairly manual. (See here for more info http://chipmunk-physics.net/release/Chi ... Properties)

So in your case, I would recommend using the unsafe functions, and possibly also surface velocities if you don't like the way the ends collide.

As for making multiple bodies, springs, etc. Try to keep it simple first. The demo application has code for controlling objects with the mouse using temporary joints. Try something like that first. It's going to feel the most solid to your players. Adding more bodies, joints, etc is just going to increase the latency.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Hexasoft
Posts: 7
Joined: Wed May 04, 2016 10:51 am
Contact:

Re: Extending pad?

Post by Hexasoft »

Thanks for your quick answer.
I will try without managing surface velocities first.

For the control maybe I did not express myself correctly, but yes (it is what I done previously based on the examples).

Thanks again.
--
Hexasoft
Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests