Users browsing this thread: 2 Guest(s)
Game Maker problem - collision and bouncing
#1
So I have some extensively annoying collisions in my game (not due to GM, though, but to my inability to well-ly program this stuff Tongue ) and I've posted this on two forums and haven't found a solution. Sad

It's a minigame, and four players are bouncing around on a spring mushroom thingy, and I want them to bounce off of each other. The thing is it's horrendously bugged, and they get stuck. A lot. They typically don't get stuck in the air, but they occasionally get spontaneously stuck to each other on the bouncer, and sometimes even 3-4 people get stuck simultaneously.
Anyone know how I can fix this?

info for player 1:
Code:
Information about object: objP1Bounce

Sprite: sprMarioBounce
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: sprPlayersBounceMask

Create Event:
execute code:

friction=global.bouncefriction


Step Event:
execute code:

if keyboard_check(vk_right) && hspeed>-global.bouncemaxspeed && place_free(x-hspeed,y)
{hspeed+=global.bouncehspeed}

if keyboard_check(vk_left ) && hspeed<+global.bouncemaxspeed && place_free(x+hspeed,y)
{hspeed-=global.bouncehspeed}

if place_free(x,y+1)
{gravity=1
gravity_direction=270}

else
{gravity=0}

if hspeed>global.bouncemaxspeed
{hspeed=global.bouncemaxspeed}

if hspeed<-global.bouncemaxspeed
{hspeed=-global.bouncemaxspeed}

if !(speed=0) {image_angle+=global.bouncespinspeed}

if vspeed>25{vspeed=25}
if vspeed<-25{vspeed=-25}


Collision Event with object objBouncer:
execute code:

//bounce off
if !place_free( x+0,y+1)
{move_contact_all(270,5)}

move_contact_solid(direction,-1);
move_bounce_solid(1);

//double vspeed because it's a trampoline
vspeed=vspeed*2
sound_play(sndBounce)

other.image_speed=0.25

Collision Event with object objP2Bounce:
execute code:

move_bounce_all(1)
instance_create(x,y,objClash)
sound_play(choose(sndBarrelDamage1,sndBarrelDamage2,sndBarrelDamage3))


Collision Event with object objBouncerBlock:
execute code:

move_contact_solid(direction,12)
vspeed=0


Other Event: Outside Room:
execute code:

move_wrap(1,0,1)

Player 2 is practically exactly the same, except a few AI discrepancies are thrown in. Players 3 and 4 are just child objects of player 2.

I have tried dozens of things, making them solid, unchecking precise collision checking, doing a circular mask, and nothing for me is working.
Thanked by:
#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:


Forum Jump: