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«First 1 2 Next»
#21
02/03/2008 (9:16 am)
@Alan

If you ever find the bug to the multiplayer thing, please let me know so I can change it.
#22
02/03/2008 (9:26 am)
I think I got that multiplayer glitch down. I have fixed the flying.cs file.
#23
02/04/2008 (10:18 am)
@Tyler

We'll try to run it soon and let you know. I'd gone about fixing it a different way that had worked, but wasn't sure what else I'd broke doing it. Thanks for the update.

.
#24
02/07/2008 (4:36 pm)
So how did it turn out?
#25
03/03/2008 (10:17 pm)
im getting an error I can't figure out. it is:
tutorial.base/server/flying.cs (3): unknown command getFowardVector.
tutorial.base/server/flying.cs (3): unknown command setFowardVector.
tutorial.base/server/flying.cs (6): unknown command toggleFlying.

Does anyone have any ideas as to what I am doing wrong? It will work in the TorqueDemo_Debug (but still shows the errors) but it wont work at all in just the TorqueDemo.
this is what the code looks like in the flying.cs file that I got from the zip.
function serverCmdtoggleFlying(%client)
{
%client.player.setFowardVector(%client.player.getFowardVector());
%client.player.setTransform(%client.player.getTransform());
if (isObject(%client.player))
%client.player.toggleFlying();
}
#26
04/03/2008 (12:46 pm)
I just fixed a tiny bit of line that made the switch from flying to walking go a bit quicker, no need to re-download if you are happy with the 1.2.1

@Michael

Ok, I don't see anything wrong, but I think that you may need to recompile.
#27
06/07/2008 (7:18 pm)
Michael, I am having the same problem. Were you able to solve the problem in release mode?
#28
06/07/2008 (7:39 pm)
I guess getForwardVector and setForwardVector are added functions? I don't see them in player.cc in the folder I downloaded.
#29
06/08/2008 (8:17 pm)
No, they arent added functions. They are functions built into TGE. the getForwardVector and setForwardVector are functions that get what direction the player is facing, and sets it again.
#30
06/09/2008 (9:16 am)
I used a different resource, thanks anyway.
#31
06/09/2008 (11:57 am)
Ok, good luck with your game.
#32
06/11/2008 (3:53 pm)
@Matt - what resource did you use?
#33
09/02/2008 (9:37 pm)
Thanks buddy.. works great
#34
06/10/2009 (12:59 pm)
I also have this problem:

Mapping string: toggleFlying to index: 5
bin/server/Flying.cs (2): Unknown command getFowardVector.
Object (2143) Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
bin/server/Flying.cs (2): Unknown command setFowardVector.
Object (2143) Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
bin/server/Flying.cs (3): Unknown command toggleFlying.
Object (2143) Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject

Are there any fixes?
#35
06/10/2009 (1:16 pm)
It's one of these:

1. You placed the files in the wrong spots.
2. You did not compile correctly.
3. You used some other resource that this is not compatible with.
4. Some changes could've been made?
#36
06/10/2009 (1:27 pm)
1. I placed the files in "C:\Torque\TGE_1_5_2\engine\game"

2. I used this resource to compile :
http://tdn.garagegames.com/wiki/Torque/vs2k5

3. Haven't used any other resources at all.

4. Maybe some changes have been made I guess. I'm using 1.5.2.
#37
08/25/2009 (11:41 am)
The zip file is corrupted.
#38
10/23/2009 (5:23 pm)
Bug!
This in player.cc in the readPacketData function:
stream->read(&rot.x);
   stream->read(&rot.y);
   stream->read(&rot.z);
   stream->read(&mFlying);
   rot.x = rot.y = 0;
   setPosition(pos,rot);

Should be:
stream->read(&rot.x);
   stream->read(&rot.y);
   stream->read(&rot.z);
   stream->read(&mFlying);
   
   setPosition(pos,rot);

Otherwise after collision you lose sync with the server and server cannot correct the client properly. This makes for jerky motion. This removal of the setting rot.x and rot.y to 0 fixes that issue.
Page«First 1 2 Next»