Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

26. March 2015

 

I just started a new concept off today, please let me know if you like it.  Basically it’s a fixed duration (one hour) overview on a specific topic, in this case Blender.  The idea is to give a cross between an introduction and a tutorial on getting started with using a certain product.  In this video we look at Blender, how to configure it, how to navigate and customize the interface, what it’s composed off and the basics of operating it.

 

If there is interest, I can do “An hour with” topics that are much more focused, such as “An hour Modelling” or “An hour texturing”, etc.

 

Additionally, this is not a deep dive Blender tutorial.  Fortunately I already have one of those!  If you are looking at specifics of learning Blender, the hotkeys, etc, please start here.

 

Below is an embedded version of the video.  It is also available in full 1080p on YouTube here.

 

The Video

 

Art , ,

24. March 2015

 

In this tutorial we start looking at 3D game development using LibGDX.  We explore creating a Camera, Model, ModelInstance and look at the basics of working in 3D using LibGDX.

 

You can watch the tutorial in HD here or embedded below.  The following is the source used in this example.

 

The Source


package com.gamefromscratch;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g3d.*;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.math.Vector3;

public class Demo3D extends ApplicationAdapter implements InputProcessor {
    private PerspectiveCamera camera;
    private ModelBatch modelBatch;
    private ModelBuilder modelBuilder;
    private Model box;
    private ModelInstance modelInstance;
    private Environment environment;
   
   @Override
   public void create () {
        camera = new PerspectiveCamera(75,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        camera.position.set(0f, 0f, 3f);
        camera.lookAt(0f,0f,0f);
        camera.near =0.1f;
        camera.far = 300f;

        modelBatch = new ModelBatch();
        modelBuilder = new ModelBuilder();
        box = modelBuilder.createBox(2f,2f,2f,
                new Material(ColorAttribute.createDiffuse(Color.BLUE)),
                VertexAttributes.Usage.Position|VertexAttributes.Usage.Normal);
        modelInstance = new ModelInstance(box,0,0,0);
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight,0.8f,0.8f,0.8f,1f));

        Gdx.input.setInputProcessor(this);
   }

   @Override
   public void render () {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT|GL20.GL_DEPTH_BUFFER_BIT);

        camera.update();
        modelBatch.begin(camera);
        modelBatch.render(modelInstance,environment);
        modelBatch.end();
   }

    @Override
    public boolean keyDown(int keycode) {
        // In the real world, do not create NEW variables over and over, create
        // a temporary static member instead
        if(keycode == Input.Keys.LEFT)
            camera.rotateAround(new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), 1f);
        if(keycode == Input.Keys.RIGHT)
            camera.rotateAround(new Vector3(0f,0f,0f),new Vector3(0f,1f,0f), -1f);
        return true;
    }

    @Override
    public boolean keyUp(int keycode) {
        return false;
    }

    @Override
    public boolean keyTyped(char character) {
        return false;
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        return false;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        return false;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        return false;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        return false;
    }
}

 

The Video


Programming , , ,

22. March 2015

 

For those of you that like living on the bleeding edge, RC2 of the upcoming Blender 2.7 is now available.  If nothing else it gives you an idea of what is coming in Blender 2.74.

 

Splash 274.png

 

 

Cycles Rendering

Rl pointiness.png

  • Several improvements for BVH like making it watertight, solving several precision issues and reducing noise
  • Optimizations:
    • Black world backgrounds are now removed from the shader graph, resulting in great speed improvements
    • Various (and great!) memory optimizations

 

  • Nodes:
    • New Pointiness attribute for the Geometry node
    • Control texture space of one object by another

 

 

User Interface

Viewport FX release notes.png

  • New Viewport Compositing brings Ambient Occlusion and Depth of Field right into the Viewport!
  • View-depth can now be picked using an Eyedropper
  • Outliner:
    • An Orphaned Datablocks Mode was added for datablock management
    • Deleting of entire object hierarchies
    • Drag&Drop objects to groups

 

  • The Node Editor can now show text-blocks in frames
  • Customizable camera safe areas
  • And more!

 

Modeling

Rl split normals.png

  • Support for Custom Normals was added
  • Transferring data layers between meshes is now possible thanks to a new Mesh Data Transfer operator and modifier
  • Tools:
    • UV handling for Edge- and Vertex Slide was improved
    • Inverse-square blending for proportional-edit-mode
    • "Fit Camera View" now works for orthographic cameras as well
    • A "Split Concave Faces" tool to ensure a convex geometry was added

 

 

Particles

07 shape cut AFTER.png

  • Hair dynamics and editing tools were improved massively:
    • Support for hair collission with meshes
    • Simulation no happens using volumetric calculations for more realistic results
    • Strand bending uses a more realistic approach
    • Controlling of child hair shapes using curve widgets
    • New "Spiral" kink mode to generate spirals at hair ends
    • Toggle buttons for render and viewport visibility were added to the particle settings in the Properties Editor
  • And much more!

 

Sculpting/Painting

Release notes cavity.png

  • Brushes/Strokes:
    • Improvements to rake and random mapping
    • Line strokes now support constrains to 45 degree increments
  • Texture Painting:
    • Support for dithering for painting on byte images
    • A new tool "Cavity Mask" was added that creates masks based on mesh cavities or hills
  • And more!

 

Freestyle NPR Rendering

Blender 274 Freestyle BNPR NY2015.png

  • A great memory consumption optimization in stroke rendering was done
  • And more!

 

Animation

Rl anim.png

  • Grease Pencil:
    • New Editing tools like copy & paste strokes, duplicating active layer, ...
    • Enable eraser on the fly while drawing with "Continuous Drawing"
    • Various UI tweaks such as color swatches for Stroke and Fill colors
    • Grease Pencil data layers are now shown in the Outliner

 

  • Improvements to the action management to reduce the cases where unused actions are deleted
  • Pasting keyframes can now be done flipped
  • Using a new "Follow" option, the animation editors can now follow the time indicator
  • And more!

 

Game Engine

  • Physics:
    • The first contact point of colliding can now be accessed from Python
    • Usability improvements
  • New option "Lock Z Velocity" to avoid micro-jumping
  • And more!

 

Add-ons

  • A new Auto Tile Size Add-on helps setting up the fastest tile size for Cycles rendering
  • Import images as planes now works for Cycles as well
  • POV-Ray Renderer now supports volumetric rendering
  • FBX and OBJ now support custom normals import
  • New Python API functions
  • And more!

 

More Features

There are a lot more features that are new in Blender 2.74, so make sure to check them out!

 

It may be a minor thing, but that “fit camera view” fix is certainly going to make my life a happier thing.  Full release notes are available here.  You can download the RC2 release here.  Or wait 2-4 weeks for the full release.

Art, News

19. March 2015

 

In this tutorial we are going to take a look at two key topics in Godot game development, Collision Detection and Physics Simulations.  Collision Detection is simply detecting if two objects overlap.  Physics on the other hand simulates the movement and interaction of game objects based on physical properties.  This of course also includes handling collisions.  There is also a video of this tutorial and this might be one of those times, due to all of the motion in the results, that you may in fact want to refer to the video even if you prefer text based tutorials.  So if you struggle to understand what I am talking about here, be sure to quickly check the video, it may have the answer.

 

You can watch the video here, or embedded below.

 

Checking for Collisions

 

Let’s start with checking collisions between two objects, in this case, two different Sprite objects.  I have created the following scene:

image

It’s simply two sprite objects side by side.  I then attached a script to the one on the left.  This script updates the position of the left sprite until a collision occurs, at which point it resets to the beginning and does it all over again.  Like so:

anim

 

Let’s take a look at the script now:

extends Sprite

var start_pos = Vector2()
var box1 = null
var box2 = null

func _ready():
   set_process(true)
   start_pos = get_pos()
   box1 = RectangleShape2D.new()
   box2 = RectangleShape2D.new()



func _process(delta):
   # Get a reference to the other sprite
   var sprite2 = get_node("/root/SceneRoot/Sprite 2")
   
   # Update our location
   self.move_local_x(0.1)
   
   # set the boundaries of each RectangleShape2D to those of the texture making up our sprite
   # values are relative to center, thus half width and height
   box1.set_extents(Vector2(self.get_texture().get_size().width/2,self.get_texture().get_size().height/2))
   box2.set_extents(Vector2(
sprite2.get_texture().get_size().width/2,sprite2.get_texture().get_size().height/2)) #Now check to see if box1 at sprite1's pos collided with box2 and sprite2's position if(box1.collide(get_transform(),box2,sprite2.get_transform())): set_pos(start_pos) # it did, so reset position to beginning, what's old is new again!

Essentially what you are doing here is creating a RectangleShape2D using the boundaries of each Sprite’s texture image.  AKA, creating a rectangle the size of the texture.  You then check if box1 at the transformed position of Sprite1 collides with box2 at the transformed position of Sprite2.  Of course, since they both use the same texture map, you don’t actually need to create two different RectangleShape2D objects!  Also, since the size never changes, you don’t actually need to set_extents() in process().  There are a number of simple shape classes that can be used to check for collisions such as concave and convex polygons, circles and even rays ( for mouse picking ).

 

This is one way to check for simple collisions.  However you will quickly find it gets unwieldy as you add more and more objects and have to check them against each other.  Fortunately the physics engine makes this process a whole lot easier.

 

Physics Simulations

 

Now that we looked at a way to test for collisions, lets move on and discuss the physics system.  Basically a physics engine simulates movement using complex math, calculating how items interact with each other and external forces like gravity.  The physics simulation then updates, either on a fixed or per frame basis, a set of objects with the new locations calculated by the simulation.  You then update your visible game objects positions accordingly.  In Godot however, you don’t generally need to perform that last step, it’s done automatically.

 

Let’s start with an extremely simple example, gravity.

 

First we start by creating a RigidBody2D node:

image

 

Next, parented to the RigidBody2D node, create a sprite node.  I am using the default icon.png that comes with Godot.  Your heirarchy should look like this:

image

 

… and that’s it.  You have now created a physics object that gravity will be applied to.  Run your game and you should see:

anim2

 

Now let’s pause a second to see exactly what is happening here.

 

First, let’s start with the RigidBody2D part…  There are three kinds of physics objects you can use in your 2D game world:

image

The biggest difference is how they are dealt with by the simulation.

 

A RigidBody can be thought of as a typical physics object.  It’s the most processing intensive, but it’s also got the most functionality.  Unless you have a reason otherwise, if something needs physics, it’s probably a rigid body.  This is a physics object that can move, can collide with other objects and itself by collided with.

 

Next up is the StaticBody2D.  This is an unmoving object in your world.  Basically things can hit it, it can be hit, but it doesn’t move.  It also takes a lot less processing power to handle.  Generally things like the world, or invisible but unmoving triggers will be static bodies.

 

Finally is KinematicBody2D.  This is a physics object that doesn’t have the range of functionality of a rigid body ( for example, you cant apply force to it ), but can move and can collide with other physics objects.  The biggest thing about a Kinematic body is that its motion is generally controlled directly by you no the physics simulation.  Generally this is the character sprite.  You want the physics simulation to react to its actions, but you generally control those movements directly in code.

 

So, those are the three major types of physics objects, now let’s look at global settings.  You notice how gravity is being applied to our simulation automatically?  Where is this coming from?

 

The answer is trust ole project settings:

image

 

So… what do those values means?  Well this is one of the nice things about working entirely in Godot.  In many physics engines like Box2D, you work in meters, then have to translate from meters to pixels when transforming your sprites.  In godot, these values are in pixels.  So a gravity value of 98 means gravity moves at 98 pixels per second.

 

Now what about Rigid Body settings?  Well let’s take a look:

image

 

Mass Friction and Bounce are the most commonly used values.  Hey, aren’t mass and weight the same thing?  Nope, not exactly.  Mass is the amount of “stuff” that composes and object, while weight is the amount that stuff weighs.

 

Consider the classic question “What weighs more, a ton of bricks or a ton of feathers?”  Both objects would have identical weights ( one ton ), but vastly different masses.  In some ways it can be easier to think of mass instead as density. 

 

Friction on the other hand is how it slides in contact with another surface.  Picture sliding a mouse down a surface on a 45 degree angle.  If one surface was rubber and the other was glass, the mouse is going to move at vastly different rates.  Friction controls this.   Bounce is often refered to as restitution.  This is the amount of, well, bounce in an object.  Or how much it reacts to a collision.  A rubber ball has a higher “Bounce” value, while a brick is almost 0.  Another key concept is sleep, this is the ability to turn the Rigid Body off during calculations, determines if it is or isn’t used as part of the over all simulation.  Linear and Angular velocity finally are the default movement values of the object.

 

Collisions Physics Style

 

Now let’s take a look at how collisions are handle using a Physics engine.  Let’s change the above scene to add another physics item, this time a static body, like so:

image

 

The top sprite has a RigidBody2D as it’s parent.  The bottom has a StaticBody2D for a parent.  Now we need to define a collision volume for each one, just like we did back at the beginning.  Simple add a new node to each Body ( not the sprite, it’s parent! ) of type CollisionShape2D, so your hierarchy looks like this:

image

 

Then for each CollisionShape2D, you need to pick a bounding shape.  With the CollisionShape2D selected in Inspector simply select the Shape dropdown and pick the one that is best suited:

image

Finally, size it so it covers the collide-able portions of your sprite:

image

 

Now when you run the game:

anim3

 

Tada!  Collisions calculated by the physics engine.  Now you can play around a bit with the physical properties of your Rigid Body and see how it reacts differently.

 

In this case we used a simple box for our collision detection, and that works well for box shaped objects.  But if your object isn’t box or circle shaped, what do you do?  Enter CollisionPolygon2D:

image

 

It works exactly the same as CollisionShape2D, but you can define the shape yourself.  Remove one of the CollisionShape2D nodes and replace it with a CollisionPolygon2D node.  With the Collision node selected, you will notice a new option in the 2D window:

image

 

Click the pen, and you can now draw a polygon around your object:

image

 

And once closed:

image

A MUCH more accurate representation of your object for collisions!

 

Kinematic Nodes

 

Finally let’s look at KinematicBody2D objects.  These are special in that the physics engine doesn’t control their motion, you do.  They can however collide with entities in the physics world.  Generally speaking, this is how you would create your character.  Unlike RigidBodies you cannot apply forces or impulses.  Instead you move them directly.  Let’s create a simple example:

 

First add a KinimaticBody2D to your scene, add a sprite and collision shape for it, like so:

image

 

Now apply a script to the KinematicBody2D with the following code:

extends KinematicBody2D



func _ready():
   set_process(true)
   
func _process(delta):
   move(Vector2(0.04,0))

We are simply moving the body by 0.4 pixels per update.  As you can see from the results however collisions will occur between your game code controlled object and the physics simulation:

anim4

 

There is obviously quite a bit more to the physics simulation.  You can create joints and springs and define what objects collide with other objects, but that covers most of the basics.  Be sure to watch the video if you struggle, as it covers things in a bit more detail!

 

The Video

 

Programming , ,

17. March 2015

 

MonoGame, the popular cross platform spin-off the now dead XNA framework has just released version 3.3.

 

For the official release notes:

 

This is a short summary of all the changes in this release:

  • Support for vertex texture fetch on Windows.
  • New modern classes for KeyboardInput and MessageBox.
  • Added more validation to draw calls and render states.
  • Cleaned up usage of statics to support multiple GraphicsDevice instances.
  • Support Window.Position on WindowsGL platform.
  • Reduction of redundant OpenGL calls.
  • Fullscreen support for Windows DX platform.
  • Implemented Texture2D SaveAsPng and SaveAsJpeg for Android.
  • Improved GamePad deadzone calculations.
  • We now use FFmpeg for audio content building.
  • BoundingSphere fixes and optimizations.
  • Many improvements to Linux platform.
  • Various fixes to FontTextureProcessor.
  • New Windows Universal App template for Windows Store and Windows Phone support.
  • Many fixes to reduce garbage generation during runtime.
  • Adding support for TextureFormatOptions to FontDescriptionProcessor.
  • XNA compatibility improvements to FontDescriptionProcessor.
  • Resuscitated the unit test framework with 100s of additional unit tests.
  • BoundingFrustum fixes and optimizations.
  • Added VS2013 project templates.
  • Moved to new MonoGame logo.
  • Added MSAA render target support for OpenGL platforms.
  • Added optional content compression support to content pipeline and runtime.
  • TextureCube content reader and GetData fixes.
  • New OpenAL software implementation for Android.
  • Xact compatibility improvements.
  • Lots of Android fixes and improvements.
  • Added MediaLibrary implementation for Android, iOS, Windows Phone, and Windows Store.
  • Added ReflectiveWriter implementation to content pipeline.
  • Fixes to Texture2D.GetData on DirectX platforms.
  • SpriteFont rendering performance optimizations.
  • Huge refactor of ModelProcessor to be more compatible with XNA.
  • Moved NET and GamerServices into its own MonoGame.Framework.Net assembly.
  • Runtime support for ETC1 textures for Androud.
  • Improved compatibility for FBXImporter and XImporter.
  • Multiple SpritBatch compatibility fixes.
  • We now use FreeImage in TextureImporter to support many more input formats.
  • MGFX parsing and render state improvements.
  • New Pipeline GUI tool for managing content projects for Windows, Mac, and Linux desktops.
  • New implementation of content pipeline IntermediateSerializer.
  • All tools and content pipeline built for 64-bit.
  • New documentation system.
  • Implement web platform (JSIL) stubs.
  • Lots of fixes to PSM.
  • Added Protobuild support for project generation.
  • Major refactor of internals to better separate platform specific code.
  • Added MGCB command line tool to Windows installer.

 

Monogame runs on Windows, Mac and Linux and is available for download here.  They have also announced that they are going to a more frequent release schedule, something I always view as a good move.

News ,

Month List

Popular Comments

Godot Engine 2.1 Released
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


9. August 2016

 

After a few release candidates, Godot Engine just released version 2.1.  If you’ve never heard of the Godot Engine, it’s a popular MIT licensed open sourced 2D/3D game engine, we previously featured it in the Closer Look series in addition to a pretty massive tutorial series, should you wish to learn more.  Godot 2.1 focused heavily on usability issues, the kind of things that make a developers life smoother on a daily basis.Godot

 

 

Features of Godot Engine 2.1 include:

    • new asset sharing platform
    • new plugin api
    • dynamic font support
    • fully internationalized editor UI
    • editor visual customization
    • user customizable key bindings
    • live script reloading
    • profiler and frame profilers
    • remote scene inspector
    • HIDPI/Retina display support
    • drag and drop support
    • contextual menus
    • script editor improvements
    • improved asset pipeline
    • improved resource preview and thumbnails
    • new animated sprite features

You can read a great deal more about these new features in the release post.

 

This feature takes a hands-on look at the new functionality available in Godot 2.1:

GameDev News

blog comments powered by Disqus

Month List

Popular Comments