Boomerang and hockshot
by Tom · in Torque Game Engine · 10/21/2005 (1:52 pm) · 6 replies
Hi,
i am somewhat new to torque script and i was wondering how i would be able to create a boomerang that can collent item and damage enemy's. also how could i make a hockshot that pulls my main character to a certain object if that object was hit by the hockshot. (think Zelda ) . also, i am close to buying th TGE (like in one or two weeks i will have enough money:))
i am somewhat new to torque script and i was wondering how i would be able to create a boomerang that can collent item and damage enemy's. also how could i make a hockshot that pulls my main character to a certain object if that object was hit by the hockshot. (think Zelda ) . also, i am close to buying th TGE (like in one or two weeks i will have enough money:))
#2
10/22/2005 (9:10 am)
Alright, thanks:) hmmm, it seems i should have posted this after i bought the TGE and after i tried some code..lol sry about that
#3
a hookshot could work undet the same principle. do a containerraycast from the player to the hookshot distance; if it collides with pretty much anything, get the distance it is away, and the direction vector (both returned from containerraycast, I believe), and increment your player to the hookshot position through translation.
sound good?
--Grant
10/25/2005 (9:06 pm)
You could do a containerraycast(), From the player to the max distance of the boomerang which would return the object the boomerang would hit... and then determine if the boomerang could bring it back or not... if it can, have the boomerang go the distance between you and the object (which is returned by containerraycast as well, I believe), and bring it back.a hookshot could work undet the same principle. do a containerraycast from the player to the hookshot distance; if it collides with pretty much anything, get the distance it is away, and the direction vector (both returned from containerraycast, I believe), and increment your player to the hookshot position through translation.
sound good?
--Grant
#4
and maybe a servercmd funtion in the "commands.cs" script that looked a little like this:
and bound the 'b' key to use the boomerang in config.cs like this:
and maybe a makeshift boomerang model like this...
then you would be good to go man.
I'm going to post a boomerang and hookshot tutorial on my website [http://www.grantmcneil.com] in about a week for you, and anyone else whom wants to look into the idea of scripting such things.
--Grant
10/26/2005 (10:21 am)
So if you were to say, have a file called Boom.cs that looked something like this:datablock ItemData(BoomData)
{
shapeFile = "~/data/shapes/Boom/boom.dts";
category = "Weapons";
className = "Weapon";
pickupname = "a boomerang";
};
function BoomData::getbusy(%datablock, %player, %found, %obj)
{
echo("Object found!" SPC %vec);
%obj.setTransform(%player.getTransform());
%datablock.IncBoom(%player, %found, %obj);
}
function BoomData::IncBoom(%datablock, %player, %found, %obj)
{
if(getword(%obj.getTransform(), 0) < getword(%found.getTransform(),0)+1 && getword(%obj.getTransform(), 0) > getword(%found.getTransform(),0)-1 &&
getword(%obj.getTransform(), 1) < getword(%found.getTransform(),1)+1 && getword(%obj.getTransform(), 1) > getword(%found.getTransform(),1)-1)
{
echo("its there!");
%datablock.BringBack(%player, %found, %obj);
}
else
{
%PartTrans = %obj.getTransform();
%abc = vectorSub(%found.getTransform(), %obj.getTransform());
%vec = getWord(%abc, 0)/vectorLen(%abc) SPC getWord(%abc, 1)/vectorLen(%abc) SPC getWord(%abc, 2)/vectorLen(%abc);
%obj.setTransform(getWord(%PartTrans, 0)+(getWord(%vec, 0)*0.05) SPC getWord(%PartTrans, 1)+(getWord(%vec, 1)*0.05) SPC getWord(%PartTrans, 2)+(getWord(%vec, 2)*0.05) SPC getWords($PartTrans, 3, 6));
%datablock.schedule(20, "IncBoom", %player, %found, %obj, %vec);
}
}
function BoomData::BringBack(%datablock, %player, %found, %obj)
{
if(getword(%obj.getTransform(), 0) < getword(%player.getTransform(),0)+1 && getword(%obj.getTransform(), 0) > getword(%player.getTransform(),0)-1 &&
getword(%obj.getTransform(), 1) < getword(%player.getTransform(),1)+1 && getword(%obj.getTransform(), 1) > getword(%player.getTransform(),1)-1)
{
echo("Done!");
%player.pickup(%found, "1");
%player.pickup(%obj, "1");
}
else
{
%abc = vectorSub(%player.getTransform(), %obj.getTransform());
%dirvec = getWord(%abc, 0)/vectorLen(%abc) SPC getWord(%abc, 1)/vectorLen(%abc) SPC getWord(%abc, 2)/vectorLen(%abc);
echo(%dirvec);
%obj.setTransform(getWord(%obj.getTransform(), 0)+getWord(%dirvec, 0)*0.05 SPC getWord(%obj.getTransform(), 1)+getWord(%dirvec, 1)*0.05 SPC getWord(%obj.getTransform(), 2)+getWord(%dirvec, 2)*0.05 SPC getWords(%obj.getTransform(), 3, 6));
%found.setTransform(%obj.getTransform());
%datablock.schedule(20, "BringBack", %player, %found, %obj);
}
}and maybe a servercmd funtion in the "commands.cs" script that looked a little like this:
function serverCmdBoom(%client)
{
%player = %client.player;
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, 20);
%start = %player.getEyeTransform();
%end = vectorAdd(%start, %vec);
%found = ContainerRayCast(%start, %end, $TypeMasks::ItemObjectType, %player);
if(%found)
{
%obj = new Item()
{
dataBlock=BoomData;
static=true;
rotate = true;
};
%obj.getDataBlock().getbusy(%player, %found, %obj);
}
else
{
echo("Nothing found : (");
}
}and bound the 'b' key to use the boomerang in config.cs like this:
moveMap.bindCmd(keyboard, "b", "commandToServer(\'Boom\');", "");
and maybe a makeshift boomerang model like this...
then you would be good to go man.
I'm going to post a boomerang and hookshot tutorial on my website [http://www.grantmcneil.com] in about a week for you, and anyone else whom wants to look into the idea of scripting such things.
--Grant
#5
thank you so much for your help:)
this is truly amazing. the script and the whole thing. wow. like it would most likely take me couple of months do come up with this. (because i have almost never time to work on it) so thank you so much:)
10/26/2005 (2:37 pm)
Wow, Grant McNeilthank you so much for your help:)
this is truly amazing. the script and the whole thing. wow. like it would most likely take me couple of months do come up with this. (because i have almost never time to work on it) so thank you so much:)
#6
02/18/2006 (9:14 pm)
I am trying to implement this and am having difficulty. is there somewhere where a more complete walkthough on how to set up this weapon is located? Greatly appreciated...
Torque Owner Chris "C2" Byars
Ion Productions