Ray Cast, The Last Chance
by Caleb · in Torque Game Engine · 08/09/2006 (9:29 am) · 7 replies
Sorry to keep posting on the same question but this is the only thing standing between me and a v1.0 demo.
If nobody can answer this in the next few days, I'll stop plaguing the forum with this question.
Here is all my code:
and in script:
vecStart and vecEnd are global variables that store the node positions.
Now every thing should work fine, except I can't use these
getImageTransform( imageData->damageStartNode, &startTrans );
getImageTransform( imageData->damageEndNode, &endTrans );
outside of a ShapeBase function.
I believe everything would work fine if I could call getNodePositions(), but I can't.
I could do somthing like:
ConsoleMethod(ShapeBase, getNodePositions, void, 2, 2, "")
{
object->getNodePositions(0);
}
However in script, what would be my object calling getNodePositions. I don't think you can setup a ShapeBase datablock (not ShapeBaseData) and use it to call my ConsoleMethod getNodePositions().
It seems like it would be something simple but it's got me stump, and it seems like I'm so close yet so far from being done with a demo. I don't know what to do.
Thanks for any help you can give me.
If nobody can answer this in the next few days, I'll stop plaguing the forum with this question.
Here is all my code:
void ShapeBase::getNodePositions(U32 imageSlot)
{
MountedImage& image = mMountedImageList[imageSlot];
ShapeBaseImageData* imageData = image.dataBlock;
//Node Positions of the Player's Ray Nodes
getImageTransform( imageData->damageStartNode, &startTrans );
getImageTransform( imageData->damageEndNode, &endTrans );
//The positions
vecStart = startTrans.getPosition();
vecEnd = endTrans.getPosition();
}
void ShapeBaseImageData::castSwordRay()
{
RayInfo swordRay;
static U32 swordMask = ShapeBaseObjectType;
if(gServerContainer.castRay(vecStart, vecEnd, swordMask , &swordRay))
{
rayCollide = true;
}
else
{
rayCollide = false;
}
}
ConsoleMethod(ShapeBaseImageData, rayCollision, bool, 2, 2, "")
{
object->castSwordRay();
return rayCollide;
}and in script:
function getRayCollision()
{
shortsword.rayCollision();
if (shortsword.rayCollision() $= true)
{
//do stuff
}
}vecStart and vecEnd are global variables that store the node positions.
Now every thing should work fine, except I can't use these
getImageTransform( imageData->damageStartNode, &startTrans );
getImageTransform( imageData->damageEndNode, &endTrans );
outside of a ShapeBase function.
I believe everything would work fine if I could call getNodePositions(), but I can't.
I could do somthing like:
ConsoleMethod(ShapeBase, getNodePositions, void, 2, 2, "")
{
object->getNodePositions(0);
}
However in script, what would be my object calling getNodePositions. I don't think you can setup a ShapeBase datablock (not ShapeBaseData) and use it to call my ConsoleMethod getNodePositions().
It seems like it would be something simple but it's got me stump, and it seems like I'm so close yet so far from being done with a demo. I don't know what to do.
Thanks for any help you can give me.
#3
08/09/2006 (4:35 pm)
Make your castSwordRay function a member of ShapeBase instead? I don't think ShapeImageData is used for much more than storing the statemachine data. It's not even it's own object, it's just part of the ShapeBase it's mounted to.
#4
It's been like a dog chasing it's tail. If I make rayCollision() so can call it in script it can't call castSwordRay(), If I make castSwordRay() so I can call it from rayCollision() I can't call getNodePositions(). And if I make getNodePositions() so I can call it from castSwordRay(), I can't use getImageTransform() to get my node positions.
PLEASE HELP MEEEEE!
08/09/2006 (5:11 pm)
Believe me, I've tried it. making all the functions a member of ShapeBase would let me call getNodeNodePositions() from castSwordRay or rayCollision(), but then how would I call castSwordRay or rayCollision()? So far I haven't been able to find a way to call ShapeBase functions from script.It's been like a dog chasing it's tail. If I make rayCollision() so can call it in script it can't call castSwordRay(), If I make castSwordRay() so I can call it from rayCollision() I can't call getNodePositions(). And if I make getNodePositions() so I can call it from castSwordRay(), I can't use getImageTransform() to get my node positions.
PLEASE HELP MEEEEE!
#5
For instance, you would make raycollision a player method that takes a slot number and figures out if the weapon in that slot (sword, axe, etc.) is intersecting. If it is, you can then invoke some sort of "I hit something" method on the datablock for that ShapeBaseImage.
Most of the melee resources on this site use this method or one very similar, so for each weapon you basically define a datablock and define a script function to call when the weapon hits something. If you look at one or more of those resources you can see how they do it.
08/09/2006 (6:05 pm)
You can't really use torquescript to interact directly with ShapeBaseImage objects such as a sword your player is holding. The best you can do is ask the player about a ShapeBaseImage he/she has mounted on a mount point (i.e., hand).For instance, you would make raycollision a player method that takes a slot number and figures out if the weapon in that slot (sword, axe, etc.) is intersecting. If it is, you can then invoke some sort of "I hit something" method on the datablock for that ShapeBaseImage.
Most of the melee resources on this site use this method or one very similar, so for each weapon you basically define a datablock and define a script function to call when the weapon hits something. If you look at one or more of those resources you can see how they do it.
#6
Its been very frustrating for me so thanks for your patience.
08/10/2006 (8:18 am)
I think I understand, but I still don't know how I would do it. Could you give me an example?Its been very frustrating for me so thanks for your patience.
#7
I'd replace
You'd have to do stuff like:
The %weaponslot is the number from %player.mountImage(). You'd then call getNodePositions with the number.
Hope this helps. I know my mind is a mess, but thats the cost of understanding Torque. ;)
--Ricky
EDITS:
* Fixed tags.
08/10/2006 (9:59 am)
You'd move the functions into Player. You could then use ShapeBase::getMountedImage(U32 imageSlot) to access the mounted weapon and all of the data you'd need. (You may need to make functions inside ShapeBaseImageData to access private members.)I'd replace
MountedImage& image = mMountedImageList[imageSlot]; ShapeBaseImageData* imageData = image.dataBlock;with a call to getMountedImage.
You'd have to do stuff like:
if(%player.rayCollision(%weaponslot) == true)
{
%player.getMountedImage(%weaponslot).doSomething(); // Note that getMountedImage returns a DataBlock, not an instance. All of the dynamic data is stored in the ShapeBase.
}The %weaponslot is the number from %player.mountImage(). You'd then call getNodePositions with the number.
Hope this helps. I know my mind is a mess, but thats the cost of understanding Torque. ;)
--Ricky
EDITS:
* Fixed tags.
Associate Orion Elenzil
Real Life Plus
player is a shapebase.
playerdata is not.
ie, %player.getNodePositions(),
not %player.getDatablock().getNodePositions().