A slight detour

Taking a detour to play around with some things

Yes, I decided that I want to build a game. Yes, I also decided to build some small games first before embarking on the main idea I have. And yes, I also also will take some detours just for fun and/or experimentation along the way!

The first such detour was playing around with moving the camera around and some quaternion math.

The Detour

Wheeeeeeee.

animated clip of a cylinder & cone & plane spinning around (one frame per 8-compass directions)

Spin spin sugar

The above clip is only the camera rotating (and the “player” staying in the same position with no rotations applied).

Another approach I tried was fixing the camear over the player’s shoulder and rotating the player instead. The code for this option feels like there should be a better way to implement it, but this is the first thing I got to have the behaviour I wanted: rotate the player (with its camera) by 1rad per tick, and move forward/backward along that rotated angle by 0.1units per tick.

if let Some(player) = context.scene.graph[self.player].cast_mut::<Pivot>() {
    let mut angle = 0.0f32;
    if self.move_left {
        angle = 1.0f32.to_radians();
    } else if self.move_right {
        angle = -1.0f32.to_radians();
    }
    let rotation = UnitQuaternion::from_axis_angle(&Vector3::y_axis(), angle);
    let trans = player.local_transform_mut();
    trans.set_rotation(trans.rotation().deref() * rotation);

    let mut pos_update = Vector3::zero();
    if self.move_up {
        pos_update.z = 0.10f32;
    } else if self.move_down {
        pos_update.z = -0.10f32;
    }
    pos_update = trans.rotation().deref() * pos_update;
    Log::info(format!("Moving player by {:?}", pos_update));
    trans.set_position(trans.position().deref() + pos_update);
}

User input handling

… I also added a camera bobbing based on the elapsed time (code not shown, but it’s just height+sin(t)).

animated clip of a cylinder moving poorly around a scene

Go my dude, go!

The Real Game

I’ve also been spending some time fleshing out my main ideas. I’m used to doing design docs in my profession life as a software engineer, so I don’t know why I was surprised to learn that game devs write a Game Design Doc (GDD) before diving into a project (which are basically the same thing). It make so much sense! I was already making copious notes, so this is just a sort of formalisation.

For some fun reading, here are two GDDs from old games:

aimeeble@blog

the blog of aimeeble


devlog3: Taking a detour to mess around with some input and camera stuff.

By Aimee, 2024-01-02


Tagged: