Math help- Verlet physics problem


today tried follow tutorial on simple verlet physics in flash. tutorial taught me how create classes points , springs (which attached points together) , calculate gravity , springs tension, etc.

 

but i'm having problem. followed tutorial fine , triple checked code make sure matched, i'm still stuck.

 

so, when run program without calculating springs' movement, works fine, gravity works well, etc., when try add in spring calculation, totally flips out, , shape gets destroyed points , springs flying every way.

 

here code spring calculation, , can upload complete source necessary.

 

[code]

public function contract():void
{
var dx:number = pointb.x - pointa.x;//point , b points have x , y value.
var dy:number = pointb.y - pointa.y;
var l:number = math.sqrt(dx * dx + dy * dy);
var difference:number = length - l;//length initial length of spring
var offx:number = (difference * dx / l);
var offy:number = (difference * dy / l);
pointa.x -= offx;
pointa.y -= offy;
pointb.x += offx;
pointb.y += offy;
}

[/code]

if kind of stuff , can code, appreciate it.

 

thanks!



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support