User Tools

Site Tools


160209 - Mech Locomotion

Movement's pretty important to the game. I've decided to take the same approach Mechwarrior 2 did:

  • 1-0 on the keyboard controls the throttle
    • [1] is idle, [2]-[0] increase in speed
  • Backspace toggles reverse
  • [a] and [d] physically turn the mech
    • It's important to remember that mouselook and the targeting reticule are separate from turning the mech

State Machine

So, to control movement (except for rotation), we need a state machine. The basic states are

  • Idle
  • Moving
    • Forward
    • Reverse

Technically jumpjets should be in here too, but I'm not worrying about that right now.

Changes in the throttle change the state from Idle to Moving (or vice versa). If the throttle is != [1], the state is Moving. Otherwise, the state is Idle. Additionally, a machine inside Moving (more a toggle, really) determines whether to move forwards or backwards; this is switched with [Backspace].

Mech Rotation

This one's pretty simple. [a]/[d] turn the mech left/right. This isn't part of the state machine, since you can turn the mech whenever you like. (This might change once I implement jumpjets, as turning with jumpjets probably shouldn't be a thing.)

Terrain Handling

So this is where things might start to get a little dodgy, but I'm thinking about it so I should write about it. The basics of moving the mech sound like they'll work perfectly well using Unity's physics systems on a flat surface. They might also work on a slope, but I'm not sure how much I want to rely on the built-in physics engine. Not much of this game will rely on real-world physics, so I'm thinking that I might have to do some basic raycasting and handle movement directly instead of with any sort of rigidbody. I always get hung up on this shit, so instead of trying to find the “right” way to do it, I'm just going to play with a few ways and pick one that seems to work best.

So slopes. Here's how I think would be best to handle it:

  1. Raycast from the center of the mech to the bottom of the feet
  2. If a surface is hit…
    1. Push the mech up along Y so the bottoms of the feet are at the point of intersection along Y
    2. Get the dot product. If it's greater than whatever threshold we deem too steep, push the mech away from the surface a small amount along the surface's normal
  3. Otherwise, apply gravity
blog/160209_mech-locomotion.txt · Last modified: 2016/02/09 12:24 by admin