Game Development Community

Crossbow + create object

by Sam3d · in Torque Game Engine · 07/12/2004 (6:00 pm) · 6 replies

Hi,

Would appreciate any pointers to creating an object, say a boulder, at the location of a projectile hit.

Does that require a recompile or can it be done with script?

Either way, suggestions of where to insert code appreciated.

(I can create new datablocks and insert them).

#1
07/12/2004 (6:13 pm)
Projectile::oncollision
{
spawn rock
}
#2
07/12/2004 (6:19 pm)
Sam,

As Gonzo is alluding to, you can simply create a new object at the point of collision in your Projectile::onCollision() method. (Entirely in script)

Something like:

function CrossbowProjectile::onCollision(%ProjDB,%Proj,%Trgt,%Fade,[b]%Pos[/b],%Norm)
{
    new rock() {
        position = [b]%Pos[/b];
    }
}

Edit - Had to pretty that up a bit. :)
#3
07/12/2004 (7:41 pm)
Great, this works... if there is a more efficient node to use, please enlighten me.

function CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{  
	
	echo("normal: " @ %normal);
	
    new TSStatic(){
         position = %pos;
       //  rotation = "0 0 -1 2.29206";
         scale = "1 1 1";
         shapeName = "~/data/interiors/rocks/rock1.dts";
         showTerrainInside = "0";
      };

etc.


Now, of course, the issue is alignment to the terrain.

How do I get the rotation value? Something to do with %normal ?

Would fxShapeReplicator be easier?

thanks,
sam
#4
07/12/2004 (7:51 pm)
Which rotation do you want? rotation of the particle when it hits?
#5
07/12/2004 (7:54 pm)
Well... maybe.

I'd like to roughly align the new rock to the terrain slope, if possible.
#6
07/13/2004 (4:00 pm)
I see this in fxShapeReplicator.cc

ShapeRotation = RayEvent.normal * mFieldData.mTerrainAlignment;

Is there a way to do this in script?

Still trying to align shapes created during play to the terrain.