Player Controlled Missiles[SinglePlayer]
by CSMP · 04/06/2010 (6:08 pm) · 27 comments
This is not Networked.(Host will fire missile)
Thanks to eb for the Torque File System:
http://torque.abigholeintheweb.com/public_system/useruploads/Player Controlled Missiles_Working.zip
Below resource MUST be installed for the barrel angle to work correctly.
(Thanks to Orion Elenzil for the resource and Bryce for bringing it to my attention)
SetForwardVector Resource: http://www.torquepowered.com/community/resources/view/15119
Tested with TGE1.5.2:
1. Place missileVehicle.cc,.h into your 'engine/game/vehicles/' folder and install the above required resource and recompile your project.(At this point your done in VC++)
2. Place missile.cs and javelin.cs into your 'server/scripts/' folder and exec from your game.cs file.
3. Place the Javelin folder into your 'data/shapes/' folder.
4. In your player.cs file add this code into your player datablock:
5. At the bottom of your commands.cs file (server side) add:
6. At the bottom of your default.bind.cs file add:
Btw: The MissileVehicle type is a HeliVehicle without Jetdn to avoid dealing with the vehicle.cc,.h changes required, so if you have the HeliVehicle resource pre-installed and do not want another module then simply rename MissileVehicle to HeliVehicle.
I have also included a basic cylinder with the required nodes to be used as a template.
This is not Networked.(Host will fire missile)
Thanks to eb for the Torque File System:
http://torque.abigholeintheweb.com/public_system/useruploads/Player Controlled Missiles_Working.zip
Below resource MUST be installed for the barrel angle to work correctly.
(Thanks to Orion Elenzil for the resource and Bryce for bringing it to my attention)
SetForwardVector Resource: http://www.torquepowered.com/community/resources/view/15119
Tested with TGE1.5.2:
1. Place missileVehicle.cc,.h into your 'engine/game/vehicles/' folder and install the above required resource and recompile your project.(At this point your done in VC++)
2. Place missile.cs and javelin.cs into your 'server/scripts/' folder and exec from your game.cs file.
3. Place the Javelin folder into your 'data/shapes/' folder.
4. In your player.cs file add this code into your player datablock:
maxInv[JavelinAmmo] = 50; maxInv[Javelin] = 1;Then add this to the bottom of the file:
//----------------------------------------------------------------------------
// Missile Control
//----------------------------------------------------------------------------
function Player::MissileControl(%this, %obj)
{
echo("c3missile Mounted");
echo("c4Obj.Client#: " @ %obj.client);
echo("c4Obj#: " @ %obj);
//commandToClient(%obj.client, 'setHudMode', 'HeliPilot');
commandToClient(%obj.client, 'SetmissilePilotVehicleKeys');
$mvForwardAction = 1;
}
//----------------------------------------------------------------------------5. At the bottom of your commands.cs file (server side) add:
//------------------------------------------------------------------------------
// Javelin Missile
//------------------------------------------------------------------------------
function serverCmdCreateMissile(%client)//fixme
{
%player = %client.player;
if(%client.player$="")
return;
if(%client.player)
if(%client.player.isMounted())
return;
%vehicle = new MissileVehicle()
{
dataBlock = Missile;
};
%vehicle.mountable = true;
%vehicle.setEnergyLevel(60);
// Spawn the car 10 units in front of the player rotated so that the driver-side
// door is facing them and taking the terrain height into account
// Get the position of the player's eye
%pos = %client.player.getMuzzlePoint($WeaponSlot);
// Use the ForwardVector calculate a 10 unit offset vector
%offset = VectorScale( %client.player.getForwardVector(), 1.25 );
// Add the offset to the position to get a point 1.25 units in front of the player
%spawn = VectorAdd( %pos, %offset );
// Now get the terrain height at that point to avoid spawning the car inside a hill
// getTerrainHeight() takes an x and y position
%xy = getWord( %spawn, 0 ) SPC getWord( %spawn, 1 );
// Get a spawn point 1.25 units in front of the player but
// at the height of the terrain plus a little extra padding
%spawn = getWord(%spawn, 0) SPC getWord(%spawn, 1) SPC getTerrainHeight(%xy) + 2;
// Get the transform
%trans = %client.player.getTransform(); //default
//%trans = %client.player.getMountedImage($WeaponSlot).getMuzzleVector($WeaponSlot);
// Get the rotational axis
%axis = getWord( %trans, 3 ) SPC getWord( %trans, 4 ) SPC getWord( %trans, 5 );
// Get the ang that the player is rotated around the axis
// Compensate for inverted axis
if (getWord(%axis, 2) < 0)
%ang = -getWord( %trans, 6 );
else
%ang = getWord( %trans, 6 );
// Add the rotation to make the door face the player (270 degrees in radians)
%ang += 6.3; //default // exec("./common/scripts/server/core/commands.cs");
//%ang += 0;
// Now set the transform we calculated
%vehicle.setTransform( %spawn SPC "0 0 1" SPC %ang );
%vehicle.setForwardVector(%client.player.getMuzzleVector(0));
//%vehicle.setGravity(0);// Optional recommended :)
%vehicle.nextWeaponFire = 1;
//%vehicle.schedule(5500, "playThread", $ActivateThread, "activate");
MissionCleanup.add(%vehicle);
// Set newly spawned missile as ControlObject here
////messageClient( %client, 'MsgMountSuccess', 'c2Entering missile- %1.', %vehicle.getDataBlock().nameTag);
%client.setControlObject(%vehicle);
%player.MissileControl(%player);
////return;
}
function serverCmdUnmountmissile(%client) //Used when Missile is destroyed
{
%client.setControlObject(%client.player);
commandToClient(%client, 'RestoreMoveMap');
CommandToClient(%client, 'NormalMovement');
commandToClient(%client, 'setHudMode', 'Play');
}
//------------------------------------------------------------------------------6. At the bottom of your default.bind.cs file add:
//------------------------------------------------------------------------------
// Missile Functions
//------------------------------------------------------------------------------
function clientCmdSetMissilePilotVehicleKeys()
{
new ActionMap( MissilePilotKeys );
//MissilePilotKeys.bind( mouse, "button1", mouseFire );
//MissilePilotKeys.bind( mouse, "button2", altTrigger );
MissilePilotKeys.Bind( keyboard, "d", moveleft ); //for some reason these are reverse
MissilePilotKeys.Bind( keyboard, "a", moveright );//for some reason these are reverse
//MissilePilotKeys.bind( keyboard, "w", moveforward );
//MissilePilotKeys.bind( keyboard, "s", reducethrust );
//MissilePilotKeys.bind( keyboard, "q", mouseJetdn );
//MissilePilotKeys.bind( keyboard, "e", mouseJet );
MissilePilotKeys.bind( mouse, "xaxis", missileyaw );
MissilePilotKeys.bind( mouse, "yaxis", missilepitch );
//MissilePilotKeys.copyBind( moveMap, panUp );
//MissilePilotKeys.copyBind( moveMap, panDown );
MissilePilotKeys.copyBind( moveMap, toggleFirstPerson );
MissilePilotKeys.copyBind( moveMap, toggleFreeLook );
// Miscellaneous other binds:
MissilePilotKeys.bindCmd( keyboard, "escape", "", "escapeFromGame();" );
// Use the InvertVehicleYAxis pref:
if ( $pref::Vehicle::InvertYAxis )
{
%bind = moveMap.getBinding( pitch );
%device = getField( %bind, 0 );
%action = getField( %bind, 1 );
%flags = moveMap.isInverted( %device, %action ) ? "SD" : "SDI";
%deadZone = moveMap.getDeadZone( %device, %action );
%scale = moveMap.getScale( %device, %action );
MissilePilotKeys.bind( %device, %action, %flags, %deadZone, %scale, pitch );
}
if ( isObject( moveMap ) )
moveMap.pop();
MissilePilotKeys.push();
}
function missileyaw(%val)
{
$mvYaw += getMouseAdjustAmount(%val) * 4;
}
function missilepitch(%val)
{
$mvPitch += getMouseAdjustAmount(%val) * 4;
}
function clientCmdNormalMovement()
{
$mvForwardAction = 0;
$mvPitchUpSpeed = 0;
$mvPitchDownSpeed = 0;
}
function clientCmdRestoreMoveMap()
{
moveMap.push();
}
//------------------------------------------------------------------------------Btw: The MissileVehicle type is a HeliVehicle without Jetdn to avoid dealing with the vehicle.cc,.h changes required, so if you have the HeliVehicle resource pre-installed and do not want another module then simply rename MissileVehicle to HeliVehicle.
I have also included a basic cylinder with the required nodes to be used as a template.
This is not Networked.(Host will fire missile)
About the author
Alpha Project Website: http://csmp.angelfire.com
#2
I come from china,I have six months to learn more torque, has been to achieve a mirror like TGEA 1.8 inside, but still can not find a solution, was very depressed, not sure if you have any good suggestions, help me!thank you
04/06/2010 (10:18 pm)
hello CSMP !I come from china,I have six months to learn more torque, has been to achieve a mirror like TGEA 1.8 inside, but still can not find a solution, was very depressed, not sure if you have any good suggestions, help me!thank you
#3
04/06/2010 (10:48 pm)
@ytfengchina: There is a really good demonstration of a mirror in the TGE1.5.2 demo, if you cant get ahold of that try searching through the forums.
#5
04/07/2010 (10:45 am)
SWEET!!!
#6
I'll go ahead and do that now, I know how we love to see things in action first! :)
P.S. Sorry guys connection is too slow, I'll have to try and re-upload tomorrow.
04/07/2010 (6:05 pm)
"a video"I'll go ahead and do that now, I know how we love to see things in action first! :)
P.S. Sorry guys connection is too slow, I'll have to try and re-upload tomorrow.
#7
04/08/2010 (6:09 am)
Did the changes you make correct this? so atm this is not network compatible
#8
04/08/2010 (6:12 am)
I made some changes from the original that make it work correctly, atm this is not network compatible... I am not sure how to implement the network side of this.(which I thought did work, but upon testing does not)
#9
04/08/2010 (6:20 am)
Converted over to T3D very quickly...
#10
04/08/2010 (6:23 am)
BTW.. the helicopter works perfect in networked mode in T3D. I will assume for the second that the conversion should also work fine. I have the engine side done, I will push through and do the scripts next. Once done I will publish a new resource for T3D.
#11
04/08/2010 (6:53 am)
Working good so far in T3D, reminds me of the UT guided missile. Definitely looks like it is networked.
#12
(not sure how a dedicated server would take it, but it needs to work for lan/small games anyway in my case)
Hopefully everything goes smooth on conversion.
04/08/2010 (8:18 am)
I tried to make sure to add the proper client/server functions but, for some reason if a client joins a game and fires off the missile the host actually shoots it!?(not sure how a dedicated server would take it, but it needs to work for lan/small games anyway in my case)
Hopefully everything goes smooth on conversion.
#15
Not sure exactly what you mean, I'll try and reproduce that also.
Edit: also the impactshake is being called at the host's position instead of the point of impact.
04/08/2010 (8:39 am)
I'm trying to place a couple echo's to find out where/what is really going on.Not sure exactly what you mean, I'll try and reproduce that also.
Edit: also the impactshake is being called at the host's position instead of the point of impact.
#16
Yours
%vehicle = new MissileVehicle()
{
dataBlock = Missile;
};
The modded one from the rocket launcher and weapon:onFire I am playing with now
%vehicle = new MissileVehicle()
{
dataBlock = Missile;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
04/08/2010 (8:47 am)
I think whats going on is your not telling the server that the client is different then the server. Yours
%vehicle = new MissileVehicle()
{
dataBlock = Missile;
};
The modded one from the rocket launcher and weapon:onFire I am playing with now
%vehicle = new MissileVehicle()
{
dataBlock = Missile;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
#17
04/08/2010 (11:49 am)
I have been able to mod this slightly to get it to recognize the client that shoots it. Your definitely not providing enough information to the server about the client that is shooting it. It looks like the procedures will need to be rewritten.
#18
04/08/2010 (4:28 pm)
I would have overlooked that for some time, Appreciate the help!
#19
04/08/2010 (4:42 pm)
Not a problem, I had it semi working before I had to call it quits today. I really want this in my kit now, this is exactly the type of stuff I am looking for! I removed the entire server command to spawn a missile and moved it all into the JavelinImage:onFire The first attempt to fire seemed to work semi ok, but each subsequent firing failed. It looked like what was happening is it was passing three pieces of data to the other functions and was being returned 2, but that's only guess work based on about an hour of troubleshooting.
#20
thanx for any help in advance.......Donnie
04/26/2010 (8:11 am)
Thanx for the resource, I'm trying hard to get it to work with my current weapon setup. I add everything like instructed and then tried to set it up with my current weapon cycle and inventory, however when I try to cycle to it and use it all I get is this error;opsf/server/scripts/inventory.cs (63): Unknown command onUse. Object javelin(2227) Item -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
thanx for any help in advance.......Donnie
Torque Owner CSMP
MP Studios
Edit: added functions required for the resource to work correctly and updated download link.