After much time and thought, I present the working ship cog!
The keys for flying are:
-foward/backward keys are pitch down/up
-left/right keys are yaw left/right
-strafe left/right keys are roll left/right
-spacebar activates and deactivates the shuttle
-fire (either) gives foward thrust
-crouch gives backward thrust
The symbols are mainly self-explanitory.
-ghost should be placed behind the console with a view out the front window (required in this version)
-max_foward=(0/+?/0)
-max_backward=(0/-?/0)
-rotateup=(+?/0/0)
-rotateright=(0/+?/0)
-bankright=(0/0/+?)
-stopped=(0/0/0)
Be sure to have the shuttle, console, and ghost in the EXACT same position. Otherwise they will rotate around different areas. Just move the center of the objects (not the ghost) so they are all positioned how you want them.
[edit]I almost forgot, all objects must have the same pitch, yaw, and roll otherwise they don't move together.[/edit]
If you have any questions, or I forgot to mention something, don't hesitate to ask.
You have permission to use this as long as I'm credited in the readme and cog description.
[edit2]I changed the cog to what SM said in his post
just to keep you from getting confused by my boredness [/edit2]
------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
[This message has been edited by SG-fan (edited July 21, 2003).]
Code:
# MOTS Cog Script
#
# shuttle.cog
#
# SG-fan
#
# THIS COG IS NOT SUPPORTED BE LEC
# =====================================================================
flags=0x40
symbols
thing console0
thing shuttle nolink
thing cam local
thing ghost nolink
int player local
int on=0 local
int startHealth=0 local
vector oldlookvec local
sound SwitchOffSound=deactivate02.wav local
sound camChangeSnd=beep2.wav local
vector max_foward
vector max_backward
vector rotateup
vector rotateright
vector bankright
vector stopped
vector rotation local
vector rotation1 local
vector rotation2 local
message activated
message playeraction
message pulse
message timer
message startup
end
# ========================================================================================
code
startup:
SetTimerEx(1, 321, 0, 0);
Return;
# ........................................................................................
activated:
player = GetSourceRef();
// Do not allow to activate the camera with the scope on...
if(GetCurWeapon(player) == 13) Return;
if(on) Return;
on = 1;
SetActorFlags(player, 0x80800000);
SetTimerEx(0.0000001, 54321, 0, 0);
Return;
# ........................................................................................
playeraction:
if (GetParam(0) == 0.0) // Jump
{
SetThingRotVel(cam, stopped);
ReturnEx(0.0);
}
else
if (GetParam(0) == 1.0) // Crouch
{
SetThingThrust(shuttle, max_backward);
Print("backward");
ReturnEx(0.0);
}
else
if (GetParam(0) == 2.0) // Activated
{
call stop_cam;
ReturnEx(0.0);
}
else
if (GetParam(0) == 3.0) // Fire
{
SetThingThrust(shuttle, max_foward);
Print("foward");
ReturnEx(0.0);
}
else
if (GetParam(0) == 4.0) // Strafe
{
ReturnEx(0.0);
rotation2=GetThingRotVel(cam);
If(GetParam(2) > 0)
{
if(VectorZ(rotation2)==VectorZ(bankright)) Return;
Print("bank right");
rotation2=VectorAdd(rotation2, bankright);
SetThingRotVel(cam, rotation2);
}
else if(GetParam(2) == 0)
{
if(VectorZ(rotation2)==VectorZ(bankright))
rotation2=Vectorsub(rotation2, bankright);
else if(VectorZ(rotation2)==(-1*VectorZ(bankright)))
rotation2=Vectoradd(rotation2, bankright);
SetThingRotVel(cam, rotation2);
}
else if(GetParam(2) < 0)
{
if(VectorZ(rotation2)==(-1*VectorZ(bankright))) Return;
Print("bank left");
rotation2=VectorSub(rotation2, bankright);
SetThingRotVel(cam, rotation2);
}
}
else
if (GetParam(0) == 5.0) // Turn
{
ReturnEx(0.0);
rotation1=GetThingRotVel(cam);
If(GetParam(2) > 0)
{
if(VectorY(rotation1)==VectorY(rotateright)) Return;
Print("left");
rotation1=VectorAdd(rotation1, rotateright);
SetThingRotVel(cam, rotation1);
}
else if(GetParam(2) == 0)
{
if(VectorY(rotation1)==VectorY(rotateright))
rotation1=Vectorsub(rotation1, rotateright);
else if(VectorY(rotation1)==(-1*VectorY(rotateright)))
rotation1=Vectoradd(rotation1, rotateright);
SetThingRotVel(cam, rotation1);
}
else if(GetParam(2) < 0)
{
if(VectorY(rotation1)==(-1*VectorY(rotateright))) Return;
Print("right");
rotation1=VectorSub(rotation1, rotateright);
SetThingRotVel(cam, rotation1);
}
}
else
if (GetParam(0) == 6.0) // Fwd / Bkwd Motion
{
ReturnEx(0.0);
rotation=GetThingRotVel(cam);
If(GetParam(2) > 0)
{
if(VectorX(rotation)==-1*VectorX(rotateup)) Return;
Print("down");
rotation=VectorSub(rotation, rotateup);
SetThingRotVel(cam, rotation);
}
else if(GetParam(2) == 0)
{
if(VectorX(rotation)==VectorX(rotateup))
rotation=Vectorsub(rotation, rotateup);
else if(VectorY(rotation)==(-1*VectorY(rotateup)))
rotation=Vectoradd(rotation, rotateup);
SetThingRotVel(cam, rotation);
}
else if(GetParam(2) < 0)
{
if(VectorX(rotation)==VectorX(rotateup)) Return;
Print("up");
rotation=VectorAdd(rotation, rotateup);
SetThingRotVel(cam, rotation);
}
}
else
if (GetParam(0) == 14.0) // Other Actions
{
if (GetParam(2) == 0.0) // Cycle Camera
{
if (GetCurrentCamera() == 0)
{
// We're in first person mode.
}
else
{
// We're in third person mode.
}
}
ReturnEx(1.0);
}
else
{
ReturnEx(0.0);
}
Return;
# ........................................................................................
pulse:
SetPulse(0.05);
// check that the player didn't die
if(GetThingHealth(player) < 1)
{
call stop_cam;
Return;
}
Return;
# ........................................................................................
timer:
if (GetSenderID() == 12345)
{
TeleportThing(player, ghost);
SetTimerEx(.0000001, 123, 0, 0);
}
if (GetSenderID() == 123)
{
// This is here for nothing really, just to hold a place for .0000001 of a second.
}
if (GetSenderID() == 54321)
{
TeleportThing(player, ghost);
SetTimerEx(.0000001, 1234, 0, 0);
}
if (GetSenderID() == 1234)
{
StopThing(player);
SetActionCog(GetSelfCog(), 0x7FFFFFFF);
DetachThing(player);
AttachThingToThingEx(player, shuttle, 0x8);
startHealth = GetThingHealth(player);
SetPulse(0.5);
SetCurrentCamera(0);
canpointnow = 1;
call switch_cam;
}
if (GetSenderID() == 321)
{
AttachThingToThingEx(ghost, shuttle, 0x8);
AttachThingToThingEx(console0, shuttle, 0x8);
}
if (GetSenderID() == 101)
{
SetThingThrust(shuttle, '0 0 0');
}
Return;
# ........................................................................................
switch_cam:
Print(" ");
Print(" ");
Print(" ");
Print(" ");
Print(" ");
dummy = PlaySoundLocal(camChangeSnd, 1.0, 0.0, 0);
cam = shuttle;
SetThingThrust(shuttle, max_foward);
Print("foward");
SetTimerEx(.1, 101, 0, 0);
SetTimerEx(minChangeRate, 12, 0, 0);
Return;
stop_cam:
StopThing(shuttle);
DetachThing(player);
SetTimerEx(0.0000001, 12345, 0, 0);
StopThing(player);
SetPulse(0);
on = 0;
canpointnow = 0;
dummy = PlaySoundLocal(SwitchOffSound, 1.0, 0.0, 0);
// Turn off control capture.
SetActionCog(-1, 0);
ClearActorFlags(player, 0x80800000);
Print(" ");
Print(" ");
Print(" ");
Print(" ");
Print(" ");
Return;
endThe keys for flying are:
-foward/backward keys are pitch down/up
-left/right keys are yaw left/right
-strafe left/right keys are roll left/right
-spacebar activates and deactivates the shuttle
-fire (either) gives foward thrust
-crouch gives backward thrust
The symbols are mainly self-explanitory.
-ghost should be placed behind the console with a view out the front window (required in this version)
-max_foward=(0/+?/0)
-max_backward=(0/-?/0)
-rotateup=(+?/0/0)
-rotateright=(0/+?/0)
-bankright=(0/0/+?)
-stopped=(0/0/0)
Be sure to have the shuttle, console, and ghost in the EXACT same position. Otherwise they will rotate around different areas. Just move the center of the objects (not the ghost) so they are all positioned how you want them.
[edit]I almost forgot, all objects must have the same pitch, yaw, and roll otherwise they don't move together.[/edit]
If you have any questions, or I forgot to mention something, don't hesitate to ask.
You have permission to use this as long as I'm credited in the readme and cog description.
[edit2]I changed the cog to what SM said in his post
just to keep you from getting confused by my boredness [/edit2]------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
[This message has been edited by SG-fan (edited July 21, 2003).]
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
Jack: "Why not!"
![http://forums.massassi.net/html/redface.gif [http://forums.massassi.net/html/redface.gif]](http://forums.massassi.net/html/redface.gif)
I'm working on fixing that.
...![http://forums.massassi.net/html/tongue.gif [http://forums.massassi.net/html/tongue.gif]](http://forums.massassi.net/html/tongue.gif)