Sunday, September 8, 2013

What good are rockets without something to shoot?

Enemies are here!

Yes, that's right - there's stuff to shoot now.  Defeat the rocket launcher-toting yellow pill capsules (aka placeholder graphics) before they get you!  Here's a quick summary of what's been changed with the Junk Engine in general, and ZOMG Rockets! in particular:

Junk Engine Changes

Added a fixed-size mode to the world manager

When in fixed-size mode:
  • The map has a finite size defined in chunk intervals
  • The entire map is loaded all at once
  • Gameplay is paused during world load, and the player gets a birds-eye view of construction
  • Boundaries are placed around the world to prevent actors from leaving (though you can shoot rockets off into the sunset if you want)

Added NPCs

The Game Manager now supports spawning of NPCs.  Spawning behaviour so far is very simple.  The level defines an initial number of enemies, along with a minimum active number, and the total number of NPCs for the level:
  • The initial number of NPCs are spawned after level load (or immediately, if the level isn't in fixed-size mode)
  • If the number of active NPCs drops below the minimum, additional NPCs are spawned
  • When the number of total NPCs that have been spawned meets the defined total, spawning stops
NPCs have basic AI support through the AI class.  Currently this is a simple state machine, with more advanced behaviour to come later.

ZOMG Rockets! Changes

ZOMG Rockets! has been changed to use fixed size worlds, and has basic victory and defeat conditions.  Yes, it's possible to get your ass handed to you by a Dr. Mario reject:
As usual, you can try the latest build here.

Sunday, September 1, 2013

Out With The Old (Character Controller)...

It's about character...

I wasn't entirely happy with the FPS character controller that comes stock with Unity.  While it does a good job of giving you an FPS-style feel (near-instant acceleration, turning on a dime, etc), it removes the opportunity for a bunch of physics-style gameplay as a result.  It was also total crap for smooth climbing in a cube-based world, and for some reason was often not detected properly by the block colliders.  For ZOMG Rockets!, I wanted all the physics-y fun of pure physics objects, FPS-style control, and smooth auto-climbing of one-block incremental height terrain.  So obviously something had to be done.
So I built a new character motor and input controller.  I tried to interfere with the built-in physics of the object as little as possible.  This was a bit tricky, since some of the characteristics of your standard FPS controller are decidedly against the laws of physics.  Here's how I put it together:

  • The character's attempted movement direction is entered as an impulse vector.
  • Force is applied every frame based on the current velocity compared to the maximum defined velocity and the impulse vector.  More force is applied when you're moving slower, or moving in a different direction (>90 degrees difference) than the direction you're trying to move in.
  • To speed directional changes, if grounded (standing on a surface), velocity is reduced by 20% each frame.  To allow ragdolling and being knocked around by explosions, this is suppressed temporarily when hit by an explosive blast.  It's a bit of a hack, but it works pretty well.
  • During each frame, rays are cast in the intended move direction.  If there is ground ahead higher than the player's feet, but below the maximum step height, the player object is moved up part of the way toward the new height each frame.  This is the only direct manipulation of position that is done by the controller, and it is only applied if the character is near stationary, or attempting to move in the direction it's already going.
The overall result feels pretty natural, and should serve pretty well.  And since it's using a standard capsule collider and rigidbody, it interacts beautifully with other objects for block collisions and explosion ragdolling.  I also managed to resolve the "falling through the world while building under your feet" bug (I hope - let me know if you still see it).

...and explosions

I also made a couple of adjustments to explosions.  The explosive force has been expanded and tapered somewhat - explosions now throw things around slightly outside their damage zone, and apply that force in a slightly diminishing fashion (full force at center, half force at the outside edge).  This results in more ragdolling, without being ridiculous (during testing, I accidentally set the explosion force so high I lost sight of the ground when I got launched).

Cave-ins are looking better than ever:


As always, you can play the latest build here.