Elastic physics algorithm

Blitz3D Forums/Blitz3D Programming/Elastic physics algorithm

fall_x(Posted 2005) [#1]
Hi,

I was wondering if anyone would know how to do "elastic physics" (in 2D - well actually, 1D would suffice :))?

I would have one object (x1,y1) and another (x2,y2) that's "hanging" from it with a virtual wire. It would fall down, but start bouncing back once it reaches a certain distance, then fall again and come up again, and eventually stop... and when the first object moves, it would have to either fall down again or be pulled up (depending if the object moved up or down).

I can't find a way to do this realistically, but then again, I suck at physics.

Anyone wanna help me?

Thanks!


Stevie G(Posted 2005) [#2]
I can take no credit for this as you can see .. it should help you though. Use the arrow keys ...




sswift(Posted 2005) [#3]
Stevie G is a poet, and he doesn't know it!


Stevie G(Posted 2005) [#4]
You do know that I'm Pam Ayres second cousin twice removed!!


Viperfish(Posted 2005) [#5]
Oh man!! That code is awesome! I mean it's a really simple program but the elastic effect is fantastic. It would be great to convert this to a 3d demo.

Could someone who has a good understanding of this sort of physics perhaps comment the code a bit for us. I would really love to understand how the code does what it does.


boomboommax(Posted 2005) [#6]
max version (just a quick replace of some bits, no point ooping it up just for this lil example)




RGR(Posted 2005) [#7]
I added this to GetInput()

B3D
	If KeyDown( 57 )
		p.particle = player\point
		p\x = 512	;because screen is 1024 x 768
		p\y = 384
	EndIf

BMax
	If KeyDown(key_space)
		p:particle = tmpplayer.point
		p.x = 512
		p.y = 384
	EndIf


In case the triangle gets lost (happens often enough when playing with different parameters) keep space pressed until things have calmed down.

Very useful Code snippet that you found, Stevie G - thanks!