Wednesday, April 04, 2007

Trouble Sleeping 2


Patrick, were
you referring to Unity 3d?

Thanks for the tip, but I'm kind of stuck using Gamemaker as part of my class.

More fiddling last night.

After many fruitless hours I finally discovered how to get GMPhysics working. I'm convinced at this point that part of the reason programming isn't as accessible as it could be is because programmers take so much basic knowledge for granted.

The .dll thing, for example. Gamemaker's help file says almost nothing, only some cryptic stuff about making one and that you have to initialize it . . . somehow. Good luck.

There were three things I managed to crack last night:

1. Installing GMPhysics.

The easiest thing to do would be to open up one of the included example files (Platform, Polygons, or Water). Delete all the sprites. Delete all the objects EXCEPT for the one labeled "control."

Now save the file as BlankGMPhysics or something similar. There you go.

The other thing you can do takes more work but lets you import it into a work in progress without having to start over.

The good thing about Gamemaker is you can open up multiple versions of the program. So open up one of the GMPhysics examples (I'll refer to it as Platform) and simultaneously open up your project.

Look at the Platform project. Under the Scripts tab you should see a Group labeled "GMPhysics." If you open that Group you will see seven more Groups such as "Polygon" and "World." Those are the Scripts you need to import into your project.

Select the Polygon Group. On the top of the project you will see File, Edit, Resources, Scripts, etc. Click on Scripts. The second item in the list is Export Group of Scripts. Click on that now. Name it the same as its Group name and Save.

Do the same for all of the Groups.

Now, in your own project, click on the Scripts menu. Choose Import Scripts. You should see all the Scripts you saved with the extension ".gml." Import all of them. Then, just to clean everything up, Right-click on Scripts and Create Group. Call this new Group GMPhysics. Drag-and-Drop all your imported Scripts into the GMPhysics Group.

Easy enough, right?

Now comes the real annoying part.

In the Platform project, look to the left and find the Global Game Settings. Double-click to open them. Choose the tab that says "Constants."

Now open the Global Game Settings in your own project and navigate to the Constants page. It should be blank. Press "Append." Now type in the first item from the Platform project.

Press Append again. Type in the next item down the list. And so on. And so on. Make sure to put these values in exactly as you see them.

There. That's all it takes to get GMPhysics into a project.

But that won't get it to work.

2. Getting GMPhysics to actually work.

So I was happy when I figured out how to set up a project with GMPhysics. I was ready to start tinkering.

I put in my temp graphics and hacked together some objects.

Run the game.

Nothing but errors. Error in code line 1.

Bullshit. Impossible. What the hell was going on?

I tried it again. And again. And again.

I took one of the physics examples and put my stuff in and tried it out. Errors. So many errors!

Fuck it. I tried to go to bed. It's 4 AM by now. I toss and turn. 4:30. 5:00. I feel terrible, dizzy and tired and the arthritis in my back is radiating tremblors of pain.

And all this time I'm turning over and over in my head my complete failure to get the goddamn program working. It should work, dammit!

Then it hits me. I'm House, that faraway look, the moment of inspiration, the puzzle solved.

I got up. Turned on the monitor. With all the lights out the monitor's brightness caused sharp pain in my eyes. It took a few minutes of blinking to adjust.

Here's the trick, then, for those who have lasted this long:

Remember the object labeled "control" that just seemed to sit there? It's in all the GMPhysics examples. There's a good reason it's there. It's where the whole thing is initialized.

Which means you need one of those objects in your project. If you created a blank project from one of the examples then you should already have it. If not, here's what you do.

Create a new Object. Name it objControl or something similar. Don't give it a sprite. Set its Depth to a very high number. Make sure it isn't checked Solid. It can stay Visible, however.

-Add a Create Event. Drop in a code block (under the Control tab on the far right) that says "init_physics( );" This is also where you would initialize a ground plane depending on your game type.
-Add a Step Event. Drop in a code block that says "update_bodies( );"
-Add a Game End Event. Drop in a code block that says "release_physics( );"

Now that you have your Control object comes the part that I missed. The part that frustrated me for hours.

Make sure you place your Control object into every Room in your game. That's it.

So Create a new Room. In the Objects tab choose objControl and drop it somewhere in the room.
Done.

3. Working with GMPhysics.

The nice thing about this add-in is that you can put nearly all your object's properties in its Create Event and then just call object_update( ); in the Step Event.

Now, for a beginner it's best to stick with the Body Scripts. Double-click on a Script and you should see a pretty good description of what it does and what arguments it needs. Try to ignore the external_call information at the bottom.

Let's say you have an object. A cube 16 x 16.

Do the usual Gamemaker steps - create your sprite and then your object.

Now, in your object make a Create Event. You want this to be a floor, so it doesn't need to move and won't react to any physics. There is a specific argument for this in the create_body Script called "STATIC."

In your Create Event drop a code block and put "create_body(x, y, STATIC, SHAPE_BOX, 16, 16);" That's it. You could also assign that code to a variable using the equals sign.

Just be sure you update your objects in the Step Event and destroy them in the Destroy Event.

Have fun. Get frustrated.

---

The Problem:

For some reason my physics objects are encountering an invisible collision plane. I have a STATIC ground block. All objects are SHAPE_BOX types. The boxes start in the air and fall, but won't touch the STATIC block.

On the other hand, I created an ACTOR type, so I can move around a little. The ACTOR sits fine on the STATIC block.

Which makes me think the problem is with the physics boxes.

Still, it's a lot easier than trying to fake the physics using Drag & Drop items. Which means more time I can spend tweaking my gameplay.

Hopefully.

1 comment:

Patrick said...

Yeah, I was, you should look into it once your class is over.