Author Topic: Physics2D  (Read 10660 times)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Physics2D
« on: 2011-07-24, 10:38:49 AM »
I have been lazily playing games instead of coding in my free time  :-[, but this morning, after seeing that durnurd (my brother) is working on cool new games with 2D physics, I decided to look into physics engines myself.  With a little difficulty (due to my 64-bit environment) and effort, I managed to get Physics2D.Net to compile and run its demos on my system.  It looks very cool.  I think I will start investigating how this might be integrated with SGDK2 somehow.

Physics2D Homepage
Demo Video

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 610
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Physics2D
« Reply #1 on: 2011-07-25, 05:49:42 AM »
Heh, I've been slacking off too! :p
I think that a physics engine is going to be a great upgrade to SGDK2!  I can't wait to see if it's possible. :)

Good luck!
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Physics2D
« Reply #2 on: 2011-07-25, 07:56:40 AM »
If things go well, I can integrate it simply as a new project template -- no new SGDK2 version/release necessary.  That would be pretty neat.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 610
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Physics2D
« Reply #3 on: 2011-07-25, 08:06:44 AM »
You don't plan to wrap the classes of the physics engine?  We would simply use the physics engine's library or something like that?
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Physics2D
« Reply #4 on: 2011-07-25, 04:36:45 PM »
I'm not sure yet.  I might import the code directly into the SGDK2 project, or I might refer to the DLL from the SGDK2 project (like I did with FMODEx).  I might create a parallel set of classes to represent the sprites and possibly the tiles in the physics engine, or I might create physics objects directly based on the sprites and tiles present in the project, or I might try to make the physics engine operate directly on the sprite instances.  I think all of these can be done without altering SGDK2 code.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Physics2D
« Reply #5 on: 2011-07-31, 07:25:54 PM »
Well it's not entirely clean, but it works!  Can anybody get this project to work for them too?
SGDK2PhysicsDemo.zip (213 KB)
Just load it and run it, I think.  If you want to edit sprite rules you may have to put the included DLL's into the SGDK2IDE.exe directory.

I just gotta say -- riding platforms in the real world is much harder than in typical platform games!

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 610
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Physics2D
« Reply #6 on: 2011-08-02, 05:34:41 AM »
Hi bluemonkmn!

I tried it yesterday, for about 5 minutes.  It works well for me but it crashed when I went into the moveable sprite to see it's rules.  I didn't put the Dll in the SGDK2 IDE folder like you pointed out.  Anyway, it's great!  Hard to put the box on the platform, but I succeeded after a while.  It's nice to see the impact it has on the platform: it absords the force of the impact and then goes back to where it should be.  It's pretty solid!

Did you have to use the "pusher" and "pushed" sprite categories, or does the physics engine takes care of that?
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Physics2D
« Reply #7 on: 2011-08-02, 12:11:07 PM »
There are actually very few sprite rules -- the physics engine is handling almost everything.  I think the only rules I have are to push the platform toward the next point on the path, to move the player according to the player inputs, and to move the player toward the mouse when the mouse button is pressed.  3 Rules.  But the project code *is* heavily customized -- for example, I hard-coded the addition of gravity into the project source code rather than putting it in a rule.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 610
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Physics2D
« Reply #8 on: 2011-08-02, 12:46:47 PM »
Interesting!  How do you tell the physics engine that a particular sprite is part of the simulation?  Or is it the other way around: you must tell the physics engine to ignore a specific sprite?   :)

Oh...  I guess there's still some work to do until the physics engine is easily available to everyone if a lot was hard coded.  But as a POC, this test game is great!
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Physics2D
« Reply #9 on: 2011-08-02, 08:44:01 PM »
Right now, every sprite in a layer is being added to the physics engine (as are all the tiles).  The ProcessSprites function in LayerBase checks to see if the physics engine and sprites have been fully initialized, and if not, initializes them.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Physics2D
« Reply #10 on: 2011-08-03, 03:59:58 PM »
You could use prismatic joints for moving platforms along their paths.  You just have to create a joint between the ground body and the platform and set the motorEnabled=true, maxMotorSpeed=(speed), motorTorque=(variable based on platform's weight), limitEnabled=true, lowerLimit=0, *breath* and upperLimit=(distance between current point and next point), and give it an axis pointing from its current location toward its next location with a magnitude of 1.  And then every frame, you just check the joint's limitState to see if it's AtUpper (or something like that), at which point you destroy that joint and create another for the next point.  At least, if you're using the Box2D physics engine.  I don't know how any others work.

It's as simple as that!
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2744
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Physics2D
« Reply #11 on: 2011-08-03, 04:22:32 PM »
Physics2D.Net has AngleJoint, HingeJoint, FixedAngleJoint and FixedHingeJoint.  Yeah, I thought of using joints, but I think it would end up being a lot more complicated, especially considering I would need something to anchor the other end of the joint to.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Physics2D
« Reply #12 on: 2011-08-04, 06:29:33 AM »
Well, the requirement of anchoring it to another body isn't really the problem.  Using Box2D terminology, there's just a default "ground" body that's static and doesn't have any fixtures attached to it.  Once you have that body, you can use it for every joint that really only needs one body.  The real problem is how much work it takes to set up joints.
Edward Dassmesser

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 610
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Physics2D
« Reply #13 on: 2011-08-04, 06:46:42 AM »
What would be gained by managing platform movement through the physics engine?  The usual platform seems to work pretty well.
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Physics2D
« Reply #14 on: 2011-08-04, 08:11:32 AM »
For particularly heavy objects, it might make the platform go more slowly, straining under pressure.  Or for very heavy objects, it may just not move at all, which you could change by perhaps upgrading the platform's motor with some object you have to get before you can bring the big block up the platform to push the button to continue, for example.  All of this could be done with rules, but with physics, it works more or less automatically.
Edward Dassmesser