Game Development Community

Script Based Mission Area Force Field

by Britton LaRoche · 01/08/2009 (12:13 am) · 8 comments

I'm blogging my new game development effort. I have about 4 hours I can spend on game development Monday through Thursday night. Its a tough thing to try to develop a game spending only 16 hours a week, but I think I can have something ready in about 6 months if I keep at it.

Back in the day when Amped Labs had extra cash we used to have a team of people working with me on Burger Wars. Now that times are lean, I need to do 90% of the coding and game play before we bring the team back together. The end goal being able to have the game fund its development so we can hire people full time.

I should probably turn this into a resource in its own right. After looking into the mission area force field resource (for about 2 hours trying to port the engine code to TGEA 1.8.0), I decided that most of the game engine mods were not necessary. This resource went to great lengths just to render the force field as a scene object to make it visible. I'll use other visual ques like fences buildings and terrain to show the player the mission area. If he or she tries to leave, I'll have an "invisible" force field to keep them at bay.

I borrowed the bare essential idea from the Mission Area Force Field V2 Resource (Which is a Great Resource!) and implemented my own version in about 5 minutes.

I'm all about small scope games now. I only make engine mods when absolutely necessary, and I have a new very small scope game I'm working on. My new philosophy is to accomplish the desired game feature with as absolutely little effort as possible. I thought I'd share the fruits of my new "zen coding" philosophy with the rest of the indies here at GG.

Implementing a Script Based Mission Area Force Field

Its only two script modifications for TGEA 1.8.0 and your game can have a mission area force field too.

In the game scripts and assets ... /server/scripts/player.cs
function Armor::onLeaveMissionArea(%this, %obj)
{
   // Inform the client
   %obj.client.onLeaveMissionArea();
   messageClient(%obj.client, 'default', 'A force field repelled you!');
   
	
   //spawn a projectile for effect
   %p = new (Projectile)() {
      dataBlock        = CrossbowProjectile;
      initialVelocity  = 0;
      initialPosition  = %obj.getPosition();
   };
   MissionCleanup.add(%p);
   
   //Force the player backward
   %force = GlobalMissionArea.bounce;    
   %min_x = getWord(GlobalMissionArea.area, 0);
   %min_y = getWord(GlobalMissionArea.area, 1);
   %max_x = %min_x + getWord(GlobalMissionArea.area, 2);
   %max_y = %min_y + getWord(GlobalMissionArea.area, 3);
   %x = getWord(%obj.getPosition(), 0);
   %y = getWord(%obj.getPosition(), 1);
   %vx = 0;%vy = 0;%vz = 0;    
   if (%x<(%min_x+10)) %vx = %force;
   if (%y<(%min_y+10)) %vy = %force;
   if (%x>(%max_x-10)) %vx = -%force;
   if (%y>(%max_y-10)) %vy = -%force;
   %vec = %vx @ " " @ %vy @ " " @ %vz;
   %obj.setVelocity(%vec);
}

What we do here is notify the client that they hit a force field and spawn a crossbow projectile to get their attention, then bounce them backward. You can change the projectile to a particle emitter or something.

For some reason the "MissionArea" tag in the mission files is now "GlobalMissionArea" in TGEA 1.8.0, so pop open your mission.mis file in a text editor and change your new MissionArea function to look like the following.

new MissionArea(GlobalMissionArea) {
      canSaveDynamicFields = "1";
      Enabled = "1";
      Area = "-150 -450 450 900";
      flightCeiling = "300";
      flightCeilingRange = "20";
         bounce = "50";
         locked = "true";
   };

The key here is two things:
new MissionArea(GlobalMissionArea)
bounce="50";

For earlier versions of TGE this will probably work
new MissionArea(MissionArea)

Thats it. You can easily test this with the strong hold demo. The bounce sets the force at which you are repelled. Happy coding!

Resource Lists
Great Resource List

#1
01/08/2009 (9:28 am)
This is a nice little back-up to prevent a player from accidentally escaping the play area. I always try to block them in with obvious obstacles but you never know how cunning a player can be at trying to get where they're not supposed to be. Useful!
#2
01/08/2009 (9:30 am)
Quote:I'm all about small scope games now. I only make engine mods when absolutely necessary, and I have a new very small scope game I'm working on. My new philosophy is to accomplish the desired game feature with as absolutely little effort as possible.
- an excellent approach.

as a side note, you might be interested in this resource, which makes it pretty simple to create some cylindrical-shaped force fields.
#3
01/08/2009 (9:54 am)
excellent, do you mind if I use this in my monorail kit ? We need a force field to stop people getting run over at the stations :)
#4
01/08/2009 (10:45 am)
hmm,
invisible collision geometry or physicalZones don't do the trick ?
#5
01/08/2009 (11:15 am)
@Julian everything I post on gg is free for any one to use... The same goes for all the other gg resources too
#6
01/08/2009 (11:25 am)
Orion you could use these but the "onleavemissionarea" hook is already built in to the game engine... And every mission typically has a mission area included by default. It's just the least amount of effort to get the desired effect.
#7
01/08/2009 (12:11 pm)
Adding a logging trigger to this would be great for both beta/alpha testing as well as feeding into any anti-cheating system. Thanks for the resource.
#8
01/09/2009 (5:28 am)
@Britton - thanks. I'll give you a mention in the doc credits.