Jump to content


Photo

Wind/Fan Physics


  • Please log in to reply
6 replies to this topic

#1 Madotsuki

Madotsuki

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8

Posted 03 May 2012 - 01:57 AM

I'm currently working on a game for a college class. It's a side-scrolling platformer and the mechanic involves wind. I'm having trouble getting this to work the way I'm envisioning. Essentially, I want the mechanic to behave in the same way as the fans do in Super Meat Boy. (Video example.)

The "wind" in my game right now functions more like a trampoline. I simply have a sprite that represents the direction and reach of the wind (it's a semi-transparent line) that, when collided with, changes the speed of the player. For instance, the wind that blows upward sets the player's vertical speed to -30. This flings the player into the air, but when they come back down and collide with the very tip of the sprite, instead of having that buoyant weightless effect, the player just bounces on the end.

This is good enough for the prototype that's due pretty soon, but it isn't what I want in the final game. What is the best way to go about emulating these kinds of physics in Game Maker? I've only been using the program for a couple months, I'm not very well-versed in GML, and I'm not even a programmer. If I could accomplish something similar to the Super Meat Boy video using GM's drag-and-drop functions, that would be awesome, but if GML is completely necessary, I'm down to learn enough to get by. (The problem is, I only have a couple weeks to do this.)

I've searched everywhere for a tutorial or a similar GM game, and I've found next to nothing. Any bit of advice would be greatly appreciated! Thanks!

Edited by Madotsuki, 03 May 2012 - 02:03 AM.

  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 04 May 2012 - 04:40 AM

This should do the job

The fan will push the player if he is on top of it
it will blow less if he is up high, more if close to the blades

using
distance/maxdistance = 0 to 1 value. the further from the fan the closer to 1. so we invert the scale by subtracting from 1.
1-distance/maxdistance = 1 to 0, the further, the closer to 0. 1*force = force, 0*force = 0... motion add to push.

Assumes x orig is center on the player and y orig is at his feet. you can use the player bbox_ variables to better the logic.
Assumes the vertical movement (jumping) is vspeed based


Fan
//fan create
force = 5; //force of the fan push
range = 100; //end of the fan wind

//fan end step
//go in player context
with(playerObj)
{
//if on top and in range, blow player
if(x>other.bbox_left && x<other.bbox_right && y < other.bbox_top && y > (other.bbox_top-other.range))
    motion_add(90, 1-((other.bbox_top-y)/other.range) * other.force;
}

  • 0

#3 Madotsuki

Madotsuki

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8

Posted 04 May 2012 - 11:54 PM

Thanks a ton! I'm gonna try this out pretty soon.
  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 05 May 2012 - 05:12 AM

keep me posted
  • 0

#5 _257502

_257502

    GMC Member

  • GMC Member
  • 98 posts
  • Version:Mac

Posted 11 May 2012 - 07:25 PM

I was googling how to do this, the code didn't work exactly. I had to modify it a little and use the step instead of step end but this was exactly what I needed, i'd post what i did to the code but i don't know how to post code i'm pretty new to the forums. btw, thanks a lot!

Edited by _257502, 11 May 2012 - 07:27 PM.

  • 0

#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 11 May 2012 - 07:34 PM

I was googling how to do this, the code didn't work exactly. I had to modify it a little and use the step instead of step end but this was exactly what I needed, i'd post what i did to the code but i don't know how to post code i'm pretty new to the forums. btw, thanks a lot!


without the spaces in the tag...
[ code ]
code goes here
[ / code]
  • 0

#7 _257502

_257502

    GMC Member

  • GMC Member
  • 98 posts
  • Version:Mac

Posted 14 May 2012 - 03:21 AM

Well i had to change it to a gravity and use the origin and a infan variable so releasing jump wouldn't set the vspeed to 0 but here it is all in the step event for the fan

if (instance_exists(skull_man))
{
if(self.bbox_left<skull_man.x && self.bbox_right>skull_man.x && skull_man.bbox_bottom < self.bbox_top && skull_man.bbox_bottom > self.bbox_top-75)
    {skull_man.gravity=1;
     skull_man.gravity_direction=90;}
if (skull_man.x<self.bbox_left) or (skull_man.x>self.bbox_right)
    {skull_man.infan=false;}
if(self.bbox_left<skull_man.bbox_left && self.bbox_right>skull_man.bbox_right && skull_man.bbox_bottom < self.bbox_top)
    {skull_man.infan=true;}
}

This is obviously all built off the skull man engine but being rebuilt to add several more features...

Edited by _257502, 14 May 2012 - 03:25 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users