Torque Demo help
by Adam Gardner · in Torque Game Engine · 03/24/2012 (5:22 pm) · 3 replies
Hello name is Adam,
Well I'm going to college for game design right now and have about 4 yrs of off and on c++ programming in .dlls. So I figured I would give the demo a try and possibly buy torque here in the next couple days so far I have created a flat terrain and a Non controlled bot and my AI player that I can use in a RTS game play click to move/attack game play.
I'm having troubles with a couple things right now as sometimes when I click to move some areas wont let me move on my terrain and second when I have my player fire at the Bot it shoots to the side of him by a couple feet any idea, Ill post the code for both of those in the script.
function refreshBottomTextCtrl()
{
BottomPrintText.position = "0 0";
}
function refreshCenterTextCtrl()
{
CenterPrintText.position = "0 0";
}
function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
%ray = VectorScale(%ray, 1000);
%end = VectorAdd(%start, %ray);
// only care about terrain objects
%searchMasks = $TypeMasks::TerrainObjectType | $TypeMasks::StaticTSObjectType |
$TypeMasks::InteriorObjectType | $TypeMasks::ShapeBaseObjectType | $TypeMasks::StaticObjectType;
// search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// If the terrain object was found in the scan
if( %scanTarg )
{
// Get access to the AI player we control
%ai = LocalClientConnection.player;
// Get the X,Y,Z position of where we clicked
%pos = getWords(%scanTarg, 1, 3);
// Get the normal of the location we clicked on
%norm = getWords(%scanTarg, 4, 6);
// Set the destination for the AI player to
// make him move
%ai.setMoveDestination( %pos );
// If the AI player already has a decal (0 or greater)
// tell the decal manager to delete the instance of the gg_decal
if( %ai.decal > -1 )
decalManagerRemoveDecal( %ai.decal );
// Create a new decal using the decal manager
// arguments are (Position, Normal, Rotation, Scale, Datablock, Permanent)
// AddDecal will return an ID of the new decal, which we will
// store in the player
%ai.decal = decalManagerAddDecal( %pos, %norm, 0, 1, "gg_decal", true );
}
}
function PlayGui::onMouseDown(%this, %pos, %start, %ray)
{
%ray = VectorScale(%ray, 1000);
%end = VectorAdd(%start, %ray);
// Only care about players this time
%searchMasks = $TypeMasks::PlayerObjectType;
// Search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// Get our player/actor
%ai = LocalClientConnection.player;
// If an enemy AI object was found in the scan
if( %scanTarg )
{
// Get the enemy ID
%target = firstWord(%scanTarg);
// Don't shoot at yourself
if( %target != %ai )
{
// Cause our AI object to aim at the target
// offset (0, 0, 1) so you don't aim at the target's feet
%ai.setAimObject(%target, "0 2 1");
// Tell our AI object to fire its weapon
%ai.schedule(100, "setImageTrigger", 0, 1);
%ai.schedule(150, "setImageTrigger", 0, 0);
return;
}
}
// If no valid target was found, or left mouse
// clicked again on terrain, stop firing and aiming
%ai.setAimObject(0);
%ai.schedule(150, "setImageTrigger", 0, 0);
}
Thanks for your time =]
Well I'm going to college for game design right now and have about 4 yrs of off and on c++ programming in .dlls. So I figured I would give the demo a try and possibly buy torque here in the next couple days so far I have created a flat terrain and a Non controlled bot and my AI player that I can use in a RTS game play click to move/attack game play.
I'm having troubles with a couple things right now as sometimes when I click to move some areas wont let me move on my terrain and second when I have my player fire at the Bot it shoots to the side of him by a couple feet any idea, Ill post the code for both of those in the script.
function refreshBottomTextCtrl()
{
BottomPrintText.position = "0 0";
}
function refreshCenterTextCtrl()
{
CenterPrintText.position = "0 0";
}
function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
%ray = VectorScale(%ray, 1000);
%end = VectorAdd(%start, %ray);
// only care about terrain objects
%searchMasks = $TypeMasks::TerrainObjectType | $TypeMasks::StaticTSObjectType |
$TypeMasks::InteriorObjectType | $TypeMasks::ShapeBaseObjectType | $TypeMasks::StaticObjectType;
// search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// If the terrain object was found in the scan
if( %scanTarg )
{
// Get access to the AI player we control
%ai = LocalClientConnection.player;
// Get the X,Y,Z position of where we clicked
%pos = getWords(%scanTarg, 1, 3);
// Get the normal of the location we clicked on
%norm = getWords(%scanTarg, 4, 6);
// Set the destination for the AI player to
// make him move
%ai.setMoveDestination( %pos );
// If the AI player already has a decal (0 or greater)
// tell the decal manager to delete the instance of the gg_decal
if( %ai.decal > -1 )
decalManagerRemoveDecal( %ai.decal );
// Create a new decal using the decal manager
// arguments are (Position, Normal, Rotation, Scale, Datablock, Permanent)
// AddDecal will return an ID of the new decal, which we will
// store in the player
%ai.decal = decalManagerAddDecal( %pos, %norm, 0, 1, "gg_decal", true );
}
}
function PlayGui::onMouseDown(%this, %pos, %start, %ray)
{
%ray = VectorScale(%ray, 1000);
%end = VectorAdd(%start, %ray);
// Only care about players this time
%searchMasks = $TypeMasks::PlayerObjectType;
// Search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// Get our player/actor
%ai = LocalClientConnection.player;
// If an enemy AI object was found in the scan
if( %scanTarg )
{
// Get the enemy ID
%target = firstWord(%scanTarg);
// Don't shoot at yourself
if( %target != %ai )
{
// Cause our AI object to aim at the target
// offset (0, 0, 1) so you don't aim at the target's feet
%ai.setAimObject(%target, "0 2 1");
// Tell our AI object to fire its weapon
%ai.schedule(100, "setImageTrigger", 0, 1);
%ai.schedule(150, "setImageTrigger", 0, 0);
return;
}
}
// If no valid target was found, or left mouse
// clicked again on terrain, stop firing and aiming
%ai.setAimObject(0);
%ai.schedule(150, "setImageTrigger", 0, 0);
}
Thanks for your time =]
#2
And the the moving part, my whole terrain is flat no bumps.
03/24/2012 (7:52 pm)
Ok sorry for the low description but I tried 0 0 1 but It was having the same problem what I found out is it acts like its a 0 * 1.And the the moving part, my whole terrain is flat no bumps.
#3
03/24/2012 (9:32 pm)
Hmm, it could possibly be something with the ai shooting a gun that something is wrong in that not sure only have scripts and not a ton of information.
Associate Steve Acaster
[YorkshireRifles.com]
There's you shooting problem, 2 units along Y axis and 1 up Z, change this to "0 0 1".
Not very descriptive but it could be that you're trying to move up too steep a slope (this stuff is in the player datablock under runAngle or something like that), or you could be aiming out of range, or to an area which isn't returning a raycast hit.