Thinking With Portal

I had an epiphany (well, it wasn’t an epiphany, but more of a realization that I’m a college graduate and nowhere near a path that leads to what I want to do with my life) the other day, and decided that it was time to stop playing games and start messing with them again. I had just finished another run through of the Half-Life series and decided that it was time to get back to my game modding roots. Back in the day (when I wanted to go to Art School), I started making maps for GoldSrc games (Counter-Strike, Day of Defeat, HLDM, etc…) and finished about 5 or 6 that I ended up releasing. I always wanted to make a short single player mod, but found that I lacked the honed art skill to make original content (models and textures) and the programming ability to make changes to the game so that it wouldn’t seem like 30 minutes of the original game with a face lift. But now that I’m a college graduate with a degree in Computer Science, maybe now I can make some of those code changes to make the game slightly enhanced from its parent and embrace my art roots to make some custom content that actually looks good. I decided to start my endeavor at the most logical continuation point: The Source Engine.

Actually, on reflection, it would seem more logical to pick up my game-making endeavors where I left them off: the Doom 3 engine. The Doom 3 engine is great for making maps and mods. Everything is open. You don’t need any custom tools to compile anything. Everything except the modeling program (Lightwave) ships with the game, and id software has always been stellar at being open to the modding community. Truth is I’m going with the Source Engine for two reasons: After playing with Portal for the n-th time, I had some ideas of possible modifications I could make to the code base that would enhance the game-play possibilities far greater than I could think of with any other engine; and two, all of my “game-making” buddies I hang around with work with Source on a regular basis (all of them either worked or are working on the Black Mesa Source modification for Half-Life 2).

Cracking open the hood of Source (specifically the Portal code), I see a lot of potential. I’m quite surprised at the way some of the things are done, and other things are just genius (portals are rendered by copying the view into the frame buffer, and use the stencil buffer to help with filters… absolute genius). I would like to build some kind of very quick single player mission that involves not only portal puzzle solving, but also combat with the portal gun. I first tried to see what I could get away with using what’s currently under the hood of the Orange Box SDK. I build a very quick “orange box” (no pun intended [no, seriously, it was a dev level that was a box with a light and a few entities]) to check a few things, and the results… out of the box… not a whole lot that deviates from Portal itself.

First thing I noticed is that all NPCs that aren’t npc_turret_floor or npc_turrent_ground objects do not comprehend Portals at all. I can understand this. I dig some digging through the code-base and found what seems to be the reason for this.

inside npc_turret_floor.cpp:

#ifdef PORTAL
if ( !FInViewCone( pEnemy ) || !FVisible( pEnemy ) )
{

CProp_Portal *pPortal = FInViewConeThroughPortal( pEnemy );

if ( pPortal )
{
// Translate our target across the portal
UTIL_Portal_PointTransform( pPortal->m_hLinkedPortal->MatrixThisToLinked(), vEnemyPos, vEnemyPos );

}
}
#endif

The majority of the Portal specific code seems to be inside of precompiler directives (for obvious reasons). This little snippet lives inside the function that determines how a turret searches for an enemy (the player); basically the turret is saying “if I can’t see the enemy anywhere, are there any portals I can see, and if so, can I see the enemy through the portal (UTIL_Portal_PointTransform function call)”. I haven’t actually ported this logic into any other npc classes yet (I’ll see what I can do this weekend… I really should be studying for my MS Active Directory certification test).

I only spent about an hour prowling through the source code looking for explanations as to why things were they way they were in my test level. While messing around with my box level, I jotted down a few things that I noticed were awry and want to look into changing:

  • NPCs don’t understand portals (can’t detect through portals) [see images at end of post]
    • after detection works, see if I can get the AI to follow through a portal
  • prop_physics don’t seem to inflict fall damage on NPCs (might just be incorrect settings in hammer)
  • Weapons do not understand portals (a combine soldier’s dropped weapon)
  • Ragdolls don’t understand portals
  • Cannot spawn portals underneath NPCs (except turrets)
    • Begs question, what do you do when this happens? If I spawn a portal
      link underneath a combine solder and the end of the link is on a wall
      at floor height, the damage inflicted by the trip wouldn’t kill him…
      The easy way out would just be kill him and make his ragdoll fall
      through and only build maps that allow soldiers to drop through portals
      that cause a very long fall. Also easier because of the fact that
      objects can emerge through a portal upside down in certain cases…
      this would require a metric fuck-ton of animations/conditions to kill
      the npc if he/she’s oriented a certain way, and just fall in others.
      Maybe it wouldn’t be that hard, but at first glance, this seems light a
      lot of work.
  • NPCs don’t shoot bullets (they do throw grenades though) [i hear it's a problem with the multiplayer code base, which I didn't think I was using... maybe Portal's code base is a branch of the multiplayer code base?]
  • Physics gun does not re-grab teleported prop_physics object after going through a portal (portal gun does)

Long shots ideas that will probably never get implemented:

  • HDR through portals?
  • Emulate light coming from a portal [[Extreme Long Shot (Don't have
    access to radiosity engine; probably hard to fake with it still looking
    good)]]

I’m actually kind of excited to see what kind of havoc I can make with the Source SDK.

Creating a portal in front of a Combine NPC and trying to peek-a-boo through it. Combine NPC complete ignores me, while the floor turret (off to the right, not shown) detects me no problem

After going through the portal, and then stepping back through, the Combine NPC is alerted to me, but can’t find me.

Posted: May 1st, 2009
Categories: Gaming, Programming
Tags:
Comments: No Comments.