Game Dev Diary #1: Starting from zero

EdRome - Oct 13 - - Dev Community

Introduction

Well, I was planning to publish this first diary, at least, two weeks ago. However, my plan changed due to technical issues I faced during the development and other activities that kept me busy.

I just started a whole new project from scratch, something different from what I'm used to do.

A few months ago, I imagined a story that I believed could be great to tell. Since programming is my passion (although my main job is more related to managing and data science), I decided to start from scratch with almost no knowledge of game development. I mean, I'm a gamer and I really love video games and board games, but I've never worked on developing one.

Over the last two weeks, I created a Game Design Document (GDD) to serve as a guide during development. I don't want to lose my way during the process.

Next, I got my hands on Godot (I was considering Unity, but I haven't decided yet) and started working on a prototype to test different mechanics that I want to include in the game.

Development

For my first prototype, I will be developing the following:

Divided into severa posts to not make a big one.

First, I created an empty 3D scene (Spatial node) and create the following:

  • Spatial
    • NavigationMeshInstance
      • MeshInstance - The Mesh is a block resized to look like a floor.
        • StaticBody
          • CollisionShape

If everything is done in this order, the collision shape will fit automatically to the mesh and the final map looks like this.

Image description

Once happy with the result, I selected the NavigationMeshInstance node, reduced the cell size property and clicked on Bake NavMesh.

Image description

Note: Reducing the cell size is important to make the navigation mesh as close as possible to the floor.

Isometric view

I think this is the easiest mechanic of all, to create the isometric view I create a camera and fix its configurations so it shows the desired view.

Image description

After following these steps, this is the result.

Image description

As reference I use this video

Click to move

The click to move development was made taking as reference this video and using this navigation documentation and this raycasting documentation.

Note: The video uses Godot 4 and I'm using Godot 3.5 (the reason behind this is because of an installation problem that I couldn't solve u.u)

The idea behind it is that the mouse casts a ray from its camera perspective of fix length, getting the position where the ray collides and calculating the character trajectory from its current position.

The character should be a KinematicBody (I include a dummy figure with MeshInstance) with a collision shape and a NavigationAgent. My complete scene looks like this:

Image description

I attached a script to the kinematic body that would do all the magic.

extends KinematicBody

var navigationAgent
export var speed = 10

# Called when the node enters the scene tree for the first time.
func _ready():
    navigationAgent = $NavigationAgent

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    if navigationAgent.is_navigation_finished():
        return
    moveToPoint(delta, speed)

func moveToPoint(delta, speed):
    var targetPos = navigationAgent.get_next_location()
    var direction = global_translation.direction_to(targetPos)

    var velocity = direction * speed
    move_and_slide(velocity)

func _input(event):
    if Input.is_action_just_pressed("left-click"):
        var camera = get_tree().get_nodes_in_group("Camera")[0]
        var rayLength = 100
        var from = camera.project_ray_origin(event.position)
        var to = from + camera.project_ray_normal(event.position) * rayLength

        var space_state = get_world().direct_space_state
        var result = space_state.intersect_ray(from, to)

        navigationAgent.set_target_location(result.position)

Enter fullscreen mode Exit fullscreen mode

The most complex part (casting a ray from mouse position) is made by the _input function (remember that I'm using Godot 3.5, it varies from its implementation on Godot 4.x).

The character movement from its current position to the mouse clicked position is done by the Navigation Agent inside the moveToPoint function.

. . . . . . . . . . .
Terabox Video Player