10-10-2013, 09:52 AM
(This post was last modified: 10-10-2013, 10:03 AM by Trainraider.)
I've had this problem for a long time too. Thankfully, I just started physics class in high school. I wrote this code as a script:
Use this to apply equal and opposite forces to your objects when they hit each other and that should fix all the buggyness. You can also use this script for countless other things involving forces. By the way, it says energy up there in "usage"; that's essentially the same as speed unless you start dealing with mass. If you use "5" for energy on an object at rest it will be pushed at speed "5" in whatever direction you choose.
Code:
/*
Usage: force(obj,energy,direction)
direction is in degrees
*/
var objx,objy,forcx,forcy,rx,ry,cspeed;
cspeed=argument0.speed;
objx=cos(degtorad(argument0.direction))*cspeed;
objy=sin(degtorad(argument0.direction))*cspeed;
forcx=cos(degtorad(argument2))*argument1;
forcy=sin(degtorad(argument2))*argument1;
rx=forcx+objx;
ry=forcy+objy;
argument0.direction=radtodeg(arctan2(ry,rx));
argument0.speed=sqrt(sqr(ry)+sqr(rx));