Creating trampoline effect

I wasn’t sure where to post this, but since it’s not actual code question I decided against posting in graphics section.

I want to be able to create a dynamic display object (straight line for example) that when it is hit by another object (ball for example) it deforms as a trampoline would and bounces the ball back.  

Key difficulties I want to address are:

  1. the line/trampoline can be at an angle to the hitting object and it needs to stretch accordingly

  2. depending on the width of this line/trampoline the bounce effect is affected, larger area, smaller bounce, smaller area higher bounce

I’ve scoured the google search as well as the forums and thus far I did not find anything that is directly useful.

What I see as a possibility is drawing the straight line using the newLine method, but then somehow converting it to joints instead? and possibly wrapping it into a class or a group/object with properties if I want to dress it up with some effects?

any feedback or pointers to resources/code would be greatly appreciated.  I really want to bang out a prototype within a week or so, but before I can do that I need to know if what I’m trying to accomplish is doable using corona.

Cheers!

That’s a cool idea.  Unfortunately, it’s not going to be simple to do in Box2d.  Box2d is a rigid-body physics engine, which means bodies don’t deform or change shape when they collide with other bodies.  So the question becomes, can we imitate a stretchable trampoline using a clever combination of rigid bodies and joints?

What you could try doing is constructing a “fabric” of small rectangles connected to one other with piston joints.  You might also have to set the pistons on pivot joints so that they can rotate somewhat.  You’d then set up motors on the piston joints that tend to pull the rectangles together.  When something falls on the fabric, the piston joints will get stretched, deforming the fabric, and the motors will cause the joints to snap back and “straighten” the fabric out again.  You might have to dynamically adjust the torque that the motors apply to imitate the idea that the more the fabric is stretched, the more force it will snap back with.

  • Andrew

Hi. Thanks for a quick reply. I don’t mind faking the effect as oppose to having “true” rope effect. In that case I’d appreciate any links or pointers where exactly I can find an example of what you referring to. Alternatively I don’t mind looking at other engines/solutions to achieve same effect in order to build this for iOS platform at least. I like corona for the relatively easy learning curve and nice physics engine, but at the end anything I’d chose will have some learning curve for me (coming from .net background ), as long as I can achieve what I’m trying to do. Again, appreciate any and all feedback and more direct examples / samples. I am not against some not free solutions meaning if a certain framework or engine does what I need but might require some licensing I’m ok with that. Thanks Alex

Hi Alex,

I think you’ll find that most engines use Box2d or something similar for 2d physics, so you’ll face the same challenge no matter what engine you work in.  (I could be wrong about that, but I know Box2d is quite common.)

I don’t have any examples of exactly what I was describing – I was just brainstorming an idea – but you can look through Corona’s API documentation as well as the physics demo sample apps that come with Corona to see examples of how to create physics objects and joints.

  • Andrew

Thanks Andrew.  I guess I have a choice to make, either mess around a bit with the API to see if I can achieve the desired effect (I just think that what I’m thinking off is not so un-comon) that it would be utilized at least by someone in some capacity and thus examples would be available. Or I’ll have to re-think the concept and substitute it with something simpler to accomplish… which is a much suckier option in my opinion since it kinds of kills everything else for me at that point… 

It’s good to brainstorm with someone other than myself ;) 

even better to actually work with someone to get things accomplished, but I guess this is the trade off when you trying to start something small, to see if it even makes sense or not.

I hope I’ll be able to figure out some way to achieve this effect or that someone will come through and point me in the right direction that will allow me to do this.

Thanks!

Alex

While I’m looking for the solution to stretch effect, any suggestions on how I can make the resulting line animated/dressed up with some kind of particle effects? like glowing, sparkle, etc? I can at least work on this if nothing else comes up as a solution.

Thanks!

That’s a cool idea.  Unfortunately, it’s not going to be simple to do in Box2d.  Box2d is a rigid-body physics engine, which means bodies don’t deform or change shape when they collide with other bodies.  So the question becomes, can we imitate a stretchable trampoline using a clever combination of rigid bodies and joints?

What you could try doing is constructing a “fabric” of small rectangles connected to one other with piston joints.  You might also have to set the pistons on pivot joints so that they can rotate somewhat.  You’d then set up motors on the piston joints that tend to pull the rectangles together.  When something falls on the fabric, the piston joints will get stretched, deforming the fabric, and the motors will cause the joints to snap back and “straighten” the fabric out again.  You might have to dynamically adjust the torque that the motors apply to imitate the idea that the more the fabric is stretched, the more force it will snap back with.

  • Andrew

Hi. Thanks for a quick reply. I don’t mind faking the effect as oppose to having “true” rope effect. In that case I’d appreciate any links or pointers where exactly I can find an example of what you referring to. Alternatively I don’t mind looking at other engines/solutions to achieve same effect in order to build this for iOS platform at least. I like corona for the relatively easy learning curve and nice physics engine, but at the end anything I’d chose will have some learning curve for me (coming from .net background ), as long as I can achieve what I’m trying to do. Again, appreciate any and all feedback and more direct examples / samples. I am not against some not free solutions meaning if a certain framework or engine does what I need but might require some licensing I’m ok with that. Thanks Alex

Hi Alex,

I think you’ll find that most engines use Box2d or something similar for 2d physics, so you’ll face the same challenge no matter what engine you work in.  (I could be wrong about that, but I know Box2d is quite common.)

I don’t have any examples of exactly what I was describing – I was just brainstorming an idea – but you can look through Corona’s API documentation as well as the physics demo sample apps that come with Corona to see examples of how to create physics objects and joints.

  • Andrew

Thanks Andrew.  I guess I have a choice to make, either mess around a bit with the API to see if I can achieve the desired effect (I just think that what I’m thinking off is not so un-comon) that it would be utilized at least by someone in some capacity and thus examples would be available. Or I’ll have to re-think the concept and substitute it with something simpler to accomplish… which is a much suckier option in my opinion since it kinds of kills everything else for me at that point… 

It’s good to brainstorm with someone other than myself ;) 

even better to actually work with someone to get things accomplished, but I guess this is the trade off when you trying to start something small, to see if it even makes sense or not.

I hope I’ll be able to figure out some way to achieve this effect or that someone will come through and point me in the right direction that will allow me to do this.

Thanks!

Alex

While I’m looking for the solution to stretch effect, any suggestions on how I can make the resulting line animated/dressed up with some kind of particle effects? like glowing, sparkle, etc? I can at least work on this if nothing else comes up as a solution.

Thanks!

Faced with a similar problem, I have been looking very closely at the “Bridge” demo in the samples - it seems to go some way to answering the OP

Faced with a similar problem, I have been looking very closely at the “Bridge” demo in the samples - it seems to go some way to answering the OP