by date
Experimenting with weapon collision and using mounted objects
Experimenting with weapon collision and using mounted objects
| Name: | Manjit Bedi | |
|---|---|---|
| Date Posted: | Apr 21, 2007 | |
| Rating: | Not Rated | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Manjit Bedi |
Blog post
I have finally got something work after pondering it for some time over the last few days.
The main character uses a weapon to 'swat' the bad guys in the game. In this particular scenario, the player is armed with a shovel. I was trying to think of how to imeplement it.
What I did was:
1) create a weapon object that is just using a transparent bitmap and mounted the object to the player
on a link point.
2) the weapon object script sets the collision states to false when the level is loaded
3) set the frame callback to true for the animation of the player when he is swinging the shovel down
4) the frame callback rountine turns on the weapon collision on a frame and then a few frames later
turns the collision off. The result the collision only is happening when the player is in the middle of the animation wih the frame down.
The main character uses a weapon to 'swat' the bad guys in the game. In this particular scenario, the player is armed with a shovel. I was trying to think of how to imeplement it.
What I did was:
1) create a weapon object that is just using a transparent bitmap and mounted the object to the player
on a link point.
2) the weapon object script sets the collision states to false when the level is loaded
3) set the frame callback to true for the animation of the player when he is swinging the shovel down
4) the frame callback rountine turns on the weapon collision on a frame and then a few frames later
turns the collision off. The result the collision only is happening when the player is in the middle of the animation wih the frame down.
function player::onFrameChange(%this, %frameIndex)
{
if(%frameIndex == 2)
{
echo ("shovel blade collision on");
$weapon.setCollisionActive(true, true);
}
else if(%frameIndex == 4)
{
echo ("shovel blade collision off");
$weapon.setCollisionActive(false, false);
}
}
Recent Blog Posts
| List: | 09/15/07 - Update on the game project 06/13/07 - Making an arcade style high score name entry screen 05/23/07 - Next steps - getting TGB into an arcade cabinet 04/21/07 - Experimenting with weapon collision and using mounted objects |
|---|
Submit your own resources!| Jameson Bennett (Apr 21, 2007 at 13:11 GMT) |
| J Sears (Apr 21, 2007 at 16:23 GMT) |
| Andy Hawkins (Apr 22, 2007 at 15:46 GMT) |
function BastardSword_Image::OnFire(%this, %obj, %slot)
{
%player = %obj.client.player;
%client = $pref::Player::ServerID;
if (%slot == 0)
{
%player.playThread(1,"light_recoil");
%this.PlaySchedule = schedule( 1000, 0, stopplay, %this, %player);
// check collision when sword is at front
%this.CheckFire = schedule( 400, 0, DidSwordHit, %this, %player);
}
if (%slot == 1)
{
%player.playThread(1,"slash2");
%this.PlaySchedule = schedule( 1000, 0, stopplay, %this, %player);
// check collision when sword is at front
%this.CheckFire = schedule( 400, 0, DidSwordHit, %this, %player);
}
// generate a swish sound
%knifesound = new AudioEmitter()
{
position = %player.position;
fileName = "~/data/shapes/weapons/bastard_sword/swordswish.ogg";
description = AudioClose3d; //for loud sound
preload = false;
};
%this.killit = %this.schedule(1000,"KillSwishSound",%knifesound);
}
function DidSwordHit(%this,%player)
{
cancel(%this.CheckFire);
// ~~~~ chose vector from player with short range to see if hit ~~~~~~~
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, 2); // distance we can hit from
%start = %player.getEyeTransform();
%end = VectorAdd(%start,%vec);
%found = ContainerRayCast (%start, %end, $TypeMasks::PlayerObjectType, %player);
// ~~~~~ if we got a target then damage it and create a hit sound ~~~~~~~~~~~~~
if (%found>0)
{
// ~~~~~~ hit sound emitter create ~~~~~~~~~~~
%hitsound = new AudioEmitter()
{
position = %player.position;
fileName = "~/data/shapes/weapons/bastard_sword/metalthud.ogg";
description = AudioClose3d; //for loud sound
preload = false;
};
%this.killit = %this.schedule(2000,"KillSwishSound",%hitsound);
%mypos = %player.getposition();
%transform = %found.getTransform();
%posX = getWord(%transform, 0);
%posY = getWord(%transform, 1);
%posZ = getWord(%transform, 2);
%posX = %posX;
%posY = %posY;
%posZ = %posZ + 1.8; // head
%posZ2 = %posZ - 0.2; // torso
%position = %posX SPC %posY SPC %posZ SPC 0 SPC 0 SPC 0 SPC 1;
%position2 = %posX SPC %posY SPC %posZ2 SPC 0 SPC 0 SPC 0 SPC 1;
//~~~~~ create blood splats from hit ~~~~~~~~~~~~
%this.blood1 = %this.schedule(250,"GeneratateBloodFX",%position);
%this.blood2 = %this.schedule(350,"GeneratateBloodFX",%position2);
%theirpos = %found.getposition();
%vector = VectorSub(%theirpos, %mypos);
%vector = VectorNormalize(%vector);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Damage 20 on Bastard Sword. min 5 max 25 base from BastardSword_Image datablock
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%lowerdamage = %this.damage - 5;
%upperdamage = %this.damage + 5;
%hitdamage = getRandom(%lowerdamage,%upperdamage); // random 15 - 25
//~~~~~ APPLY DAMAGE ~~~~~~~~~~~~~~~~~~~~~
%found.getDataBlock().damage(%found, %obj, %vector, %hitdamage, "Melee");
}
}
//~~~~ stop animation after one swing ~~~~~~~
function stopplay(%this,%player)
{
%player.stopThread(1);
}
//~~~~~ kill hit sound ~~~~~~~~~~~~
function BastardSword_Image::KillSwishSound(%this, %soundtokill)
{
%soundtokill.delete();
}
| Manjit Bedi (May 23, 2007 at 13:00 GMT) |
Manjit
| Manjit Bedi (May 23, 2007 at 13:36 GMT) |
I have only just started using triggers a bit - I think I can see how they work in this context.
Hmm. All good.
You must be a member and be logged in to either append comments or rate this resource.


Not Rated


