Game Development Community

dev|Pro Game Development Curriculum

Making a Player Fly

by Tyler Slabinski · 12/21/2007 (3:01 pm) · 38 comments

Download Code File

Version 1.2.2

Made a tiny adjustment to make the server use less work, no need to re-download if you have 1.2

Version 1.2.1

Corrected a line of code that made a multiplayer glitch.

Version 1.1.1

-Fixed a typo.
-Made the .sit file a .zip.

------------------------------------------------------------------------------------------------------------------------
This was originally made by Matt Fairfax, so most credits go to him. Also creds go to:

Tom Spillman: Partly fixed a major bug that made the player vibrate when flying.
Master Treb: Rewrote the code so you may toggle flight on and off.
Andy Hawkins: Cleared up some code for Tom Spilman's non-shaking flight.
Tyler Slabinski: Put some script that prevented the shaking glitch.
------------------------------------------------------------------------------------------------------------------------

In the downloaded file, you will find:

engine/game:
player.cc
player.h
server
flying.cs

INSTRUCTIONS:

In engine/game, find your player.cc and player.h files, and replace them with the newer ones in the .sit file. Use your favorite compile method to rebuild TGE. Then put your flying.cs file in your games server folder. Open up server/game.cs and find:

// Load up all datablocks, objects etc.
   exec("./camera.cs");
   exec("./editor.cs");
   exec("./player.cs");
   exec("./logoitem.cs");
   exec("./commands.cs");
Put this right under it:

exec("./flying.cs");

Now here comes the fork in the road, if your game is built off starter.fps, put this code at the bottom of your client/config.cs file:

moveMap.bindCmd(keyboard, "t", "commandToServer(\'toggleFlying\');", "");

Although, if your game is built off of tutorial.base, go to your client/default.bind.cs file and put this at the bottom:

GlobalActionMap.bindCmd(keyboard, "t", "commandToServer(\'toggleFlying\');", "");

Now once you load up your game, press t and you can fly around!

NOTE: Toggling flying on and off rapidly will confuse the engine and will shake your player.

About the author

Recent Blogs

• Some random practice
Page «Previous 1 2
#1
12/23/2007 (8:05 pm)
Nice work Tyler - I'll give it a go.
#2
12/25/2007 (12:50 pm)
I thought I put the file in to make a GUI that toggles it, I will update it when I get the chance.
#3
12/28/2007 (9:17 pm)
Very nice, though your starter.fps binding has a typo in it, \'toggleFly\' should be \'toggleFlying\'
Also, any chance of a play-by-play "what to edit and where"? If not can you atleast give me a clue as to which functions were altered in player.cc. I want to look it over but I fear having to compare two 4400 line files.
#4
01/03/2008 (12:19 pm)
Well, many functions have been altered. I will make a list of what lines were altered in a bit.
#5
01/07/2008 (10:47 am)
Has anyone using a Windows based PC been able to extract this .SIT file? I've tried Zipeg, Universal Extractor, Power Acrchiver all without any luck. Like to take a look at it, but can't seem to open the archive.
#6
01/07/2008 (2:36 pm)
Yeah I tried ExtractNow and it doesn't work. SIT file extensions have been problematic on Windows. It should be ZIP'd to make it more portable. Has anyone else tested this archive?
#7
01/08/2008 (11:18 am)
Ok, I made a .zip file instead.
#8
01/09/2008 (3:22 am)
Yep that is downloadable and I can open it. Nice work.
#9
01/09/2008 (5:12 am)
@Andy,

In the file you were able to download, was there anything else in it other than the player.cs file? I was able to open it also, but the whole file was only about 3kb and only contained the player.cs file.
#10
01/09/2008 (5:29 am)
There are two folders one called __MACOSX\Making a Player Fly containing _Flying.cs and another called Making a Player Fly and contained Flying.cs

Code inside looked like this...
function serverCmdtoggleFlying(%client)
{
    %client.player.setTransform(LocalClientConnection.player.getTransform());
    if (isObject(%client.player))
       %client.player.toggleFlying();
}

Code inside _Flying.cs was corrupted.

This does not seem like a verified or complete resource. GG and Tyler, what is the status of this resource?
#11
01/09/2008 (2:56 pm)
Ok, something was wrong with the file thinking it was read only, I fixed it.

If that file gets corrupted again, it thought it was a folder, I am working on that bug. My .cs file automatically think it's DreamWeaver junk.
#12
01/10/2008 (5:25 am)
Looks okay now Tyler - nice work.
#13
01/15/2008 (4:05 pm)
Thank you for this ressource it works well for me but I notice that the speed of my player is slow now...Have you seen that ??? do you have a solution ??? thank you
#14
01/17/2008 (12:27 pm)
It looks like your player is slower, but it isn't if you want to speed it up, try adding speed.
#15
01/18/2008 (5:48 pm)
How can I add speed ???
changing the speed camera or changing a script ???
thanks tyler for your work
... simple to set up and usefull
#16
01/23/2008 (11:54 am)
Well, I am not sure how to speed the player up, but I will try my best to do so...
#17
01/25/2008 (7:48 pm)
@Tyler,

Have been meaning to let you know this works well. Thanks for sharing.

The question I have is have you looked at this in a multi player environment? It appears when we test it in a multi player game, the player who didn't start the server transports to the location of the player that started the server on the "toggleFlying" command. I would imagine there is some way to inform the server which client is calling the command so this doesn't happen, but I'm more of an artist than a coder so I'm not sure what exactly to change. Just thought I'd note it.

Thanks again.
#18
01/30/2008 (5:29 pm)
@Alan,

Sorry, I can't seem to find any problem on multiplayer, maybe there was a typo or something, but I can't find it.
#19
01/31/2008 (2:56 am)
@Tyler,

After unzipping the download, the only entry in the "flying.cs" file is what Alan, specified above.

function serverCmdtoggleFlying(%client)
{
%client.player.setTransform(LocalClientConnection.player.getTransform());
if (isObject(%client.player))
%client.player.toggleFlying();
}

Should there be more? I get an error "flying.cs (4): Unknown command toggleFlying" when running it.
#20
01/31/2008 (3:12 am)
@Tyler,

Please ignore my previous post. I found my pilot error, it's way too late for me to be up. It works great now.

This is an excellent resource.
Page «Previous 1 2