• 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!

Creating floating enemies or objects

Erayd

Member
The title says most of what I need really. I've been looking around the web for answers to this topic and I have been experimenting but time is running short and I can't quite figure out a system to accomplish a floating enemy. I'm using the physics engine of Game Maker Studio, so I can check easily for collisions between say the player and a mob.

The biggest issue is that my Bee enemy just slowly moves down due to gravity, so I figure I would pulse the mob enemy with an upwards impulse every few steps but it was too unreliable. I don't really have any code to show since nothing I have done has really helped. Thanks for any thoughts, they are all appreciated.
 
C

Ctl-F

Guest
Define unreliable. What was it doing that you didn't like?
 
A

AlphaChannel

Guest
Perhaps adding a force every step equal to the gravity instead of bursts every few steps? I am not at my computer so atm I can't test if it works.

By unreliable Im guessing you mean unpredictable? Or do you mean just not effective?
 

woods

Member
"adding a force every step equal to the gravity instead of bursts every few steps"
how bout a combination of the burst and opposing gravity at step event.. would give it the hovering float "float" you're looking for ;o)

something like
burst = gravity +/-10
 

TheouAegis

Member
Is this a side-scroller or top down or 3D? Forest side scroller, I would consider going with the wave pattern from Pennsylvania. I tend to go with that because it's fairly easy for me to work with and manipulate. Basically the way it works is you divide the difference between the starting height and the current height by some figure like 256 (it was an 8-bit game, so they used 256). Then you subtract that value from the speed. The drawback to this is you cannot use gravity, or at least if you do use gravity you will have odd results. Try it, see if you like what happens with gravity. An idea is if you like how it works with gravity, try setting up a timer or something that will reverse the direction of gravity every so often, which should I would guess give the appearance of a semi erratic up-and-down motion. But I don't work in Physics, so....


Update: Here's a sample code I wrote up real quickly to demonstrate what I was talking about. This doesn't use physics, but if you just plug it into a new project with a bee object, you can see it work.

Create Event:
Code:
gravity = 1/16;
vspeed = 1;
hspeed = 2;
timer = (current_time & 7) << 4;
x0 = x;
x1 = x+196;
Step Variant 1:
Code:
vspeed += (ystart-y)/256;
timer -= 1;
if !timer
{
  timer = (current_time + x + y & 7) << 4;
  vspeed = 0;
  gravity = -gravity;
}
else
if abs(vspeed) > 2 vspeed = 0;
if x < x0 || x > x1 hspeed = -hspeed;
Step Variant 2 (for longer paths):
Code:
vspeed += (ystart-y)/256;
timer -= 1;
if !timer
{
  timer = (current_time + x + y & 7) << 4;
  gravity = -gravity;
}
if x < x0 || x > x1 hspeed = -hspeed;
Step Variant 3 (for shorter paths):
Code:
vspeed += (ystart-y)/256;
timer -= 1;
if !timer
{
  timer = (current_time + x + y & 7) << 4;
  vspeed = -vspeed;
}
if x < x0 || x > x1 hspeed = -hspeed;
 
Last edited:

Erayd

Member
Hey I'm very sorry I haven't been on to respond to something I myself posted. Its a 2D game, by unreliable I mean inconsistent and easily messed up. So it only works with this one object at a single density which is bad since I may want to use it for a bunch of things. Like a platform.

This is the code I wrote which added a float effect to the bee object. For now, this works. I set the speed to zero and I put it back to its starting point each update. The problem is if the player steps on the bee to drag it down, the bee pops back up above the player where it started. Which right now isn't a big deal. I'll keep in mind your idea @TheouAegis . I'm a little hesitant to use it because gravity is heavily relied upon at this moment but maybe it's worth scrapping and controlling it all myself. Physics are a little wonky to handle sometimes. Thank you all for your help!
Code:
if(float) phy_speed_y = 0;

if(currStep % modUpdates == 1){
    if(float) phy_position_y = startY;
}
[\code]
 

TheouAegis

Member
Variant 3 leaves gravity intact, so if you're changing the gravity in your world globally, that'd probably be the one to play around with. As for making the code work in a physics word, I'm not sure what exactly you'd have to do because I haven't worked with the physics engine. So however you accelerate in physics world would be what you'd modify the first line of my codes for.
 
Top