Game Development Community

Dummy object for melee collisions

by Mike Daly · in Torque Game Engine Advanced · 11/05/2007 (3:33 pm) · 7 replies

I have a melee weapon set up as follows: when the player takes a swing (the weapon itself is an image, and thus can't have collisions) a dummy StaticShape is mounted to the weapon which will do the damage. My datablock for the dummy is:

datablock StaticShapeData(dummyData)
{
	shapeFile = "~/data/shapes/weedWacker/dummy2.dts";
	emap = true;
	mountPoint = 3;
	firstPerson = false;
};

And the OnCollision for it is:

function dummyData::OnCollision(%this, %obj, %col)
{
	echo("HIT");
	%col.damage(10);
}

And here's the mounting call for the dummy object:

function serverCmdUseWeapon(%client)
{
	if(%client.player.mountedWeapon $= "bat")
	{
		echo("SWING");
		%dummy = new StaticShape(batDummy){datablock = dummyData;};
		%client.player.mountObject(%dummy, 3);
		%client.player.setActionThread(swing, 2, 30);
		schedule(600, 0, "dropDummy", %client, %dummy);//remove the dummy object after the swing
	}
}

The problem is the OnCollision is never getting called. Any help would be greatly appreciated.

Thanks

#1
11/06/2007 (7:08 am)
Does your dummy2.dts have a collision mesh?
#2
11/06/2007 (12:07 pm)
Yes-when I import the object (dummy2) itself I can collide with it, but when it mounts to the bat there is no collision.
#3
11/06/2007 (3:01 pm)
Ok, looking at your code closer "I don't think it's doing what you think it's doing" (slightly altered quote from the Princess Bride). The function mountObject mounts the scoped object to the specified object, not the other way around.

So calling:
%client.player.mountObject(%dummy, 3)
Will mount the player onto the "dummy" object on mount point 3 (think player mounting a vehicle). Considering it happens very quickly I don't think you were noticing. So, you're going to have to come up with another way to accomplish your goal. Here are some ideas off the top of my head:

1. Modify the code so that ShapeBaseImage objects process collision events.
2. Modify the code to allow for arbitrary mounting of one ShapeBase object to another ShapeBase object.
3. "Fake it" by scheduling a function to be runs shortly after the server receives the "attack" command to check the vector distance between the source and target objects to see if they are within melee "range."

The timing of #3 above can also be improved by using an Animation Trigger that activates a script callback to check the distance instead of a schedule function with a "fixed" timing.
#4
11/06/2007 (3:30 pm)
Where are you getting that definition of mountObject from? This is the only definition I've been able to find;


mountObject( objectHandle , node )

Purpose
Use the mountObject method to mount the shape specified by objectHandle to this shape at mount node.


From TDN
#5
11/09/2007 (7:29 am)
Ah sorry, I do have that backwards. However, does your player model have a Mount2 node?
#6
11/09/2007 (3:11 pm)
Yes-I can see the object mount to the correct location when he swings the weapon, and it moves with the weapon as it should, but it isn't colliding with anything. From what I understand, mounted shapes should maintain their collision meshes, but that doesn't appear to be the case.
#7
11/14/2007 (2:30 pm)
It's because in reality the object isn't moving even though you're swinging it. You'll need to roll your own collision detection code and call it manually each tick. Just sub shapebase for your weapon., makes it easier to plug in your own hooks and call them only when the weapon animation is firing. It's very easy to get broad-based player hitbox collisions doing this, incredibly hard to get anything accurate for blood splatter or lopping off limbs.