Blender 3D: Noob to Pro/Platformer: Physics Fixes



This tutorial is intended as an improvement on its prequel, Platformer: Creation and Controls, and will require files created through that tutorial. It is also recommended that you read An aMAZEing game engine tutorial as well before beginning this tutorial. It will require a familiarity with the Blender UI, simple commands (such as AKEY to select) and basic modeling skills. This tutorial will introduce the following features and improvements:

  1. only letting the character jump while touching the ground
  2. stop the character from bouncing greatly upon hitting an object
  3. where to adjust material friction

This tutorial was written for version 2.45.

Creating Your Hit Test Object


Copy the cube with SHIFT-D. Go into edit mode, select the bottom four vertices of the cube and delete them. Go back to object mode. Go to the editing panel in the buttons window. In the Link and Materials section, change the ME: value to "Square" and the OB: value to "FloorHit". In the Mesh section, there will be three buttons with the word "center" in them; Center, Center New, and Center Cursor. Press Center New. This will change the origin of the "Square" mesh to the center of all of its vertices, instead of the center of the cube you made it from. Scale it to 0.99% of the original and move it up 0.01 along Z. Now go to the shading panel and make sure you're in the Material buttons subpanel. Find Links and Pipeline, and make sure "ME is selected. Click the X next to the material selection (under the words "Link to Object"). Then select "OB" and press "Add New" and name this material "FloorHit" (again, no quotes). Make it green colored, so you can easily find it while editing, but turn on "Shadeless" and "No Mist" in the Material section and "OnlyCast" in the Links and Pipeline - Render Pipeline section and turn off "Radio", "Traceable", and "Shad(ow)buffer" in the Render Pipeline and "Shadow" in the Shaders section. This will make it completely invisible at runtime and take up little resources.

(question: it wont make it invisible it just flashes rapidly)

Making the sensor require floor contact


Now select Suzanne and go to the logic panel. Add a touch sensor called "jumpcol" (for 'jump collision') and connect it to the same AND controller as the jump keyboard sensor. Set the f to 10 and the MA: to FloorHit. This will make it so your character can only jump while it's touching something with the FloorHit material. By that same token you can link this to all of your movement-related AND controllers so that the player can't adjust it's movements in mid-air. This is a nice physics touch but for most platformer games, where mid-air dexterity is almost essential, it doesn't work. You also have to use Force and not dLoc, otherwise your character won't be able to move at all while jumping, useless your character only needs to hit things with his/her head, and not jump over gaps. Note that this still does not keep the character from jumping while touching the hit test object at the sides, so they could still jump if they were touching the side of the collision surface, but at least they can't jump in mid-air or while touching the bottom of the ground. I have yet to find a solution to this problem not involving Python.

Excessive Bouncing


Another problem with the original model, as you might have noticed, is that when you run into one of the ground cubes you bounce back a great deal. To fix this, turn to the materials panel with one of your green hit test squares selected. Under the color selectors there should be three buttons that say "RGB", "HSV", and "DYN". Select DYN, and turn the restitution most or all the way up. As you can see, you can also find the friction property from here, if you want your ground to be more or less frictional (like mud or ice).

Final Notes


Always copy your floors, their respective hit test objects, and other generic objects with ALT-D and not SHIFT-D. This keeps you from duplicating things that remain the same for every one, like the material and mesh, which quickly drain resources if not recycled. Since there's not much further you can take the Platformer without learning Python, I suggest you start looking up information on the Blender API. Some essential information is to be found in the procedural object creation tutorial. A Blend file of the tutorial's finished product is coming soon.

Note: A (possibly) simpler method for jump limitation can be found on the discussion page for this tutorial.