GM: Introduction to 3D

From GMpedia.org Wiki

Jump to: navigation, search
This article (or section) may need to be wikified to meet GMpedia's quality standards.
Please help improve this article, especially its categories, and wiki-links.

This tutorial works with...

Written for Game Maker 6.1, works with Game Maker 7

Here, I'm doing a nice and small tutorial for all you how are new to the GML and the 3D. This tutorial will show you some basic 3D. Let's start with the 3D.

The basic 3D is to make a block. How to make a block? It's easy. We just need some easy line of codes and scripts. Let's start.

Create a new script called "scr_start_3d".

In this script, make this code:

d3d_start();//starts the 3D mode 
d3d_set_perspective(true);//sets perspective to true 
d3d_set_hidden(true);//removes hidden surface 
d3d_set_lighting(false);//switch lighting off 
d3d_set_color(c_white);//set the draw color 
d3d_det_fog(true,c_white,1,1024);//draw fog 
d3d_set_culling(false);//switch culling off 
d3d_set_shading(false);//switch shading off 
texture_set_interpolation(true);//switch interpolation on 

And that's the start 3D code. Let's make the next code, the block script. Before you do this, make a background called "back_block". Make a new script called "scr_block":

d3d_draw_block(0,0,0,32,32,32,background_get_texture(back_block),1,1);//this makes a block 

This should make a 3D block there the object later on is placed. Now, to see this block, we need a "camera" to see it. So we make another script. Call the script "scr_camera". In this script, make this code:

d3d_set_projection(128,96,64,16,16,16,0,0,1);this makes the camera 

Now, when the codes are done, when need two objects:

  1. The block object
  2. The camera object

We atart with the camera. Make an object called "obj_camera". In the draw event, got to the control tab and take the "Execute a script" block and drag it to the action bar. A window pops up. Select the script, "scr_camera".

In the create event, make the same thing but change the script to "scr_start_3d". Now, the camera is done, let's make the block. Make an object called "obj_block". Put, in the draw event, the "Execute a script" and select the "scr_block" script.

Now, the objects are done. Create a new room, place the camera in the corner, and the block infront of the camera. Run the game, and there should be a block infront of you.

If it is a block there, you have finished this tutorial.

This article was originally found at the Game Maker Knowledge Base, contributed by Dennis Fredriksson.
See the talk page for details
Game Maker
Personal tools