• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Make objects that roll off and bounce when colliding with one another

N

Nyky

Guest
I'm currently trying to make a bullet-hell style game where bullets rain down and the player must guard the target using a shield. Instead of just having the bullets disappear when hit by the shield I'm trying to make it so they'll pick up some of the shields vertical/horizontal momentum depending if there is any, and also make them roll of the shield which is shaped like an upside down "U".

Helpful scripts/ tutorials would be much appreciated, I'm trying to avoid using Gamemakers built in physics engine but I'm flexible.

Thanks!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, well you have two solutions here: The first one would be to make the game use the built in physics functions, but this may be "overkill" as it would require a lot of setting up and if it's only for this one thing in the game then it's probably not a good idea and may break more things than it fixes. The other would be to add some code into the collision event that "pushes" the bullet instance out of the way. For this to work, you'd need something like this (I'm assuming the "shield" is a separate instance):

Code:
// COLLISION EVENT IN THE SHIELD OBJECT WITH THE BULLET OBJECT

// First, push the instance out of the collision
var _cdir = point_direction(x, y, other.x, other.y);
while(place_meeting(x, y, other))
{
other.x += lengthdir_x(1, _cdir);
other.y += lengthdir_y(1, _cdir);
}

// Now apply momentum based on shield movement
var _dir = point_direction(xprevious, yprevious, x, y); // get the shields movement direction
var _dis = point_distance(xprevious, yprevious, x, y); // get the shields movement "speed"
with (other)
{
motion_add(_dir, _dis); // if this is too much, then use (_dis / 10) or something like that
}
Hope that helps!
 
Top