Sword Problems
by Michael Roberts 13 · in Torque 3D Beginner · 06/08/2015 (3:50 pm) · 4 replies
Hey everyone it's me again.I really need some help with swords.OK so i have made a few scripts for the sword and executed them but whatever i do it refuses to show up in game so what is there for me to do now?
Thanks in advance,
Michael Roberts
Thanks in advance,
Michael Roberts
About the author
13 year old teen,n00b scriptor but skillful in 3d artists.Gamer 4 life
#2
06/10/2015 (1:57 pm)
the sword dosent show up in scripted section but it does load as a mesh
#3
06/11/2015 (5:22 pm)
The first step is always to make sure the scripts have compiled correctly when loaded. Check the console for any errors related to your script. It sounds like you are wanting to add a sword item to your game; an item you can run into which causes the player to pick it up, correct? If so then you would need to have an "itemData" dataBlock for it. Take a look at the full template under art/datablocks/health.cs to see how it creates the health items.
#4
datablock ItemData(sword)
{
category = "Weapon";
className = "Weapon";
shapeFile = "art/shapes/weapons/CZSword/CronoSword.dts";
mass = 12;
elasticity = 0.2;
friction = 0.6;
maxVelocity = "15.0";
pickUpName = "CRONOVIUM";
image = swordImage;
description = "A Sword created from the energy of the universe itself.";
};
datablock ShapeBaseImageData(swordImage)
{
shapeFile = "art/shapes/weapons/CZSword/CronoSword.dts";
mountPoint = 0;
eyeOffset = "0 0 0"; // 0.46=right/left 0.5=forward/backward, -0.5=up/down
// correctMuzzleVector = true;//we don't have a muzzle for a melee weapon!
className = "WeaponImage";
item = sword;
stateName[0] = "Activate";
stateTransitionOnTimeout[0] = "Ready";
stateTimeoutValue[0] = 0.5;
stateSequence[0] = "Activate";
stateSound[0] = DrawWeaponSound;
stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Fire";
stateName[2] = "Fire";
stateTransitionOnTimeout[2] = "PostFire";
stateTimeoutValue[2] = 0.8;
// stateRecoil[2] = MediumRecoil;
//you can use the stateRecoil if you want it to play the attack animation
//and have it suitably linked in the player cs,
//see below for alternative
stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateSound[2] = meleeFireSound;
stateName[3] = "PostFire";
stateTransitionOnTimeout[3] = "Ready";
stateTimeoutValue[3] = 0.1;//0.01 for 4 rps
stateAllowImageChange[3] = false;
};
function swordImage::onFire(%this, %obj, %slot)
{
%obj.setActionThread("melee");
%this.schedule(300, "Melee_attack", %obj);
}
function swordImage::Melee_Attack(%this, %obj)
{
%eyeVec = %obj.getEyeVector();
%startPos = %obj.getEyePoint();
%endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 2));
%target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);
%col = firstWord(%target);
if(%col == 0)
return;
echo(%col);
//return the ID of what we've hit
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
{
%col.damage(%obj, %pos, 15, "Sword Slash");
echo(%col.getname());
%vpos = %col.getWorldBoxCenter();
%pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());
%pushDirection = VectorNormalize(%pushDirection);
%pushVec = VectorScale(%pushDirection,1000);
%pushVec= getwords(%pushVec,0,1);
%col.applyImpulse(%vpos, %pushVec);
}
}
$melee_check2hit =
$TypeMasks::VehicleObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::StaticTSObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ForestObjectType;
06/12/2015 (5:33 pm)
its not working.and this is the script im using for the sword.datablock ItemData(sword)
{
category = "Weapon";
className = "Weapon";
shapeFile = "art/shapes/weapons/CZSword/CronoSword.dts";
mass = 12;
elasticity = 0.2;
friction = 0.6;
maxVelocity = "15.0";
pickUpName = "CRONOVIUM";
image = swordImage;
description = "A Sword created from the energy of the universe itself.";
};
datablock ShapeBaseImageData(swordImage)
{
shapeFile = "art/shapes/weapons/CZSword/CronoSword.dts";
mountPoint = 0;
eyeOffset = "0 0 0"; // 0.46=right/left 0.5=forward/backward, -0.5=up/down
// correctMuzzleVector = true;//we don't have a muzzle for a melee weapon!
className = "WeaponImage";
item = sword;
stateName[0] = "Activate";
stateTransitionOnTimeout[0] = "Ready";
stateTimeoutValue[0] = 0.5;
stateSequence[0] = "Activate";
stateSound[0] = DrawWeaponSound;
stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Fire";
stateName[2] = "Fire";
stateTransitionOnTimeout[2] = "PostFire";
stateTimeoutValue[2] = 0.8;
// stateRecoil[2] = MediumRecoil;
//you can use the stateRecoil if you want it to play the attack animation
//and have it suitably linked in the player cs,
//see below for alternative
stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateSound[2] = meleeFireSound;
stateName[3] = "PostFire";
stateTransitionOnTimeout[3] = "Ready";
stateTimeoutValue[3] = 0.1;//0.01 for 4 rps
stateAllowImageChange[3] = false;
};
function swordImage::onFire(%this, %obj, %slot)
{
%obj.setActionThread("melee");
%this.schedule(300, "Melee_attack", %obj);
}
function swordImage::Melee_Attack(%this, %obj)
{
%eyeVec = %obj.getEyeVector();
%startPos = %obj.getEyePoint();
%endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 2));
%target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);
%col = firstWord(%target);
if(%col == 0)
return;
echo(%col);
//return the ID of what we've hit
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
{
%col.damage(%obj, %pos, 15, "Sword Slash");
echo(%col.getname());
%vpos = %col.getWorldBoxCenter();
%pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());
%pushDirection = VectorNormalize(%pushDirection);
%pushVec = VectorScale(%pushDirection,1000);
%pushVec= getwords(%pushVec,0,1);
%col.applyImpulse(%vpos, %pushVec);
}
}
$melee_check2hit =
$TypeMasks::VehicleObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::StaticTSObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ForestObjectType;
Torque Owner Caleb
Default Studio Name