Projectile::onCollision
by Scott Brown · in Game Design and Creative Issues · 08/02/2010 (1:30 pm) · 8 replies
I am currently working on a project similar to a Dart Board style of game. I am having issues with the dart sticking to the wall, it only hits and disappears. I'm not sure what I need to do to get this working correctly. I am assuming this is going to be part of the Projectile DataBlock, but not nothing really seems to be working.
Any advice, assistance or a point in the right direction would be great.
Thanks,
Scott
Any advice, assistance or a point in the right direction would be great.
Thanks,
Scott
#2
08/02/2010 (6:05 pm)
I think this would work perfect Michael. Would you know where I could see an example of what this part of the impact function would look like? Or able to give me the name of a book that goes over torque script in greater detail? (I've gone through All in one game programing editions 1 and 2 looking for more)
#3
08/02/2010 (6:34 pm)
Something like this as an example. This is untested ...datablock StaticShapeData(DartShape)
{
shapeFile = "art/shapes/crossbow/projectile.dts"; // change this to your shape and path
};
// DartProjectile is the datablock name of your projectile
function DartProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
// do damage handling stuff here, if desired
// get the location and rotation of the projectile
%trans = %obj.getTransform();
// place a new shape at the location of impact using above %trans
%dart = new StaticShape()
{
datablock = "DartShape";
};
%dart.setTransform(%trans);
// make sure to add to MissionCleanup
MissionCleanup.add(%dart);
}
#4
08/02/2010 (6:38 pm)
In regards to books to learn Torque script I can only suggest that any of them can help teach some script basics and concepts. The way I learned was by simply tearing into the scripts and figuring out how things worked. If I broke it then I learned by fixing it. Just start small with the easier concepts and build upwards, always learning.
#5
08/02/2010 (6:41 pm)
Thanks Michael, this works flawlessly, can not thank you enough for your assistance
#6
Is their a better way to do it so it always faces the correct way, or do I need to play around with the transform a bit?
08/02/2010 (6:53 pm)
After some testing, it adds the model just as designed with out regard to the vector. So firing at say the side wall, it sticks but it sticks sideways.Is their a better way to do it so it always faces the correct way, or do I need to play around with the transform a bit?
#7
A quick and simple hack would be to get the player's rotation when you fire the dart, inside of your dartweaponimage::onFire()
08/02/2010 (9:51 pm)
Ooops, guess I should've tested that. The proper, although tricky, fix would be to do some vector math and storing a rotation matrix and simply adding that to the position when placing the new shape for a more accurate transform.A quick and simple hack would be to get the player's rotation when you fire the dart, inside of your dartweaponimage::onFire()
%transform = %obj.getTransform(); $throwRot = getWord(%transform, 3) SPC getWord(%transform, 4) SPC getWord(%transform, 5) SPC getWord(%transform, 6);And then inside of projectile::onCollision() change it so that the transform is concatenated from the %pos (the impact location) and the $throwRot (relative to the player's direction)
%trans = %pos SPC $throwRot;This should make the static dart shape align with the direction it was thrown - though this doesn't account for vertical look direction.
#8
08/02/2010 (10:11 pm)
Works like a charm big thanks to you Michael. Would have taken me a very long time to figure all this out with out your help, learned a lot on this one.
Associate Michael Hall
Distracted...