Users browsing this thread: 1 Guest(s)
Game Maker problem - collision and bouncing
#2
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:
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));
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.
Thanked by:


Messages In This Thread
RE: Game Maker problem - collision and bouncing - by Trainraider - 10-10-2013, 09:52 AM

Forum Jump: