Game Development Community

Few simple scripting problems.

by Phil Carlisle · in Torque Game Engine · 10/08/2002 (2:41 pm) · 8 replies

Hi Guys.

Worked on the hand 2 hand.

What I did was add a function and call to it from shapebase.cc into shapeimage.cc which basically calls a function to look for 2 dummy nodes in a dts file (damageStart and damageEnd).

This in turn transforms those mount points into world space coords and then calls a script function to do the damage.

The script function calls the raycast function which casts a ray between the two nodes and damages anything that crosses the line.

So here's a few Q's:

Whats the scriptThis object? is that the shapebase (i.e. the player?) if I use this in the raycast should it not hit the player who holds the weapon (thats one issue Ive got).

Anyway, if you want to try this, the code's in the realmwars CVS.

Phil.

#1
10/10/2002 (7:59 am)
Phil,

It sounds like you and I were heading along similar lines. I posted this in the general discussions forum yesterday. Maybe you can answer my question while I grab your code and try to answer yours?

"It seemed like such a simple idea at the time... I wanted to create a basic hand-to-hand combat system while not duplicating the work that had already been done to make the projectile system. After playing with the Armor::damage function and the projectile system calls I was able to have it give me the location of where the player was hit when you fired a bullet. So it seemed a simple leap to get it to work for a hand-to-hand combat system. I would animate the sword and when its bounding box contacted the bounding box of the player I would fire off an "invisible projectile" down the sword's length. It would have a slow rate of travel and a very short lifespan so it would not reach past the end of the weapon. The projectile would contact the character's bounding box and cause the damage while giving me the location of the damage as well.

It would be wickedly fast, and it would not require creating an additional layer of collision boxes and a testing mechanism in code. By moving the muzzlepoint and using a pattern vector of fire I could also achieve hand-to-hand damage with axes, hammers or any other hand held object.

I initially tried it out by firing off a "pattern" of projectiles that I could see that matched a simple animated sword swipe. It worked fine, cutting down my ai opponent. But for complicated sword moves trying to exactly match a pattern would use a huge number of shells and bog down the server in heavy combat. The basic idea worked fine and so I tried to move on to the next part which was to get the bounding box of the sword to fire a projectile when it encountered the bounding box of another player or aiBot.

I started by placing a muzzle point for the sword at the top of the handle so I could fire it down the blade when I collided with the opposing player...

At this point my tests ground to a screeching halt. For three days I have tried to find a way to capture the collision data in script. The sword passes thru the bot I created and does not seem to send off any indication that the object has collided. I can bump into the bot and I get messages forever... So, I am looking for two things...

1. I need a way to capture the initial collision between my sword's bounding box and the opponents bounding box so I can trigger my projectile. I know it must be there I just can't find the right function.

2. I need to make sure that the vector my projectile travels is always from the "muzzlepoint" at the top of the handle to the tip of the sword point.

Some of you math whizzes out there who know the vector and matrix calculations and are familiar with the Armor::damage function may be able to help...

Thanks in advance."
#2
10/10/2002 (9:46 am)
I'm going to need to figure this out as well so I may as well comment here.

When a character swings his weapon, it would be a thrust recoil animation with his arm and the weapon mounted to it. That action will be swift, e.g. you don't swing an axe in slow motion, you whack your opponent fast and hard as possible.

That melee animation will have some finite length to it in terms of time.

I'm thinking i can use the muzzlePoint which is at the end of the sword. Collision detection is handled by the projectile system.

The projectile will have zero range or a very small range so it doesnt go any further than the end of the sword and a very short lifetime, zero or something very small. Reload time is more lengthy. The projectile's damage is the weapon's damage and it is invisble. Just a small transparently textured triangle or cube.

The weapon states and timeout values will be tinkered with to achieve the smoothest look and to match up the models animations.

This all seems to be already in the engine. Perhaps it's time for me to try it out.

I'll keep you informed as to my progress.
#3
10/10/2002 (12:13 pm)
Get the realmwars code to see how Ive handled it.

I stuck two new nodes in, damageStart and damageEnd. I do a raycast between those two (which basically run the length of the blade).

The collision works fine, my object gets killed as expected (in pretty short order).

Only thing thats bugging me is that *I* take damage too. I just need to mask off the player holding the weapon from taking damage in some manner and it will be fine.

I'd like to do collision box collision too, but I never saw a place to create the collision box for the weapon image.

Phil.
#4
10/10/2002 (3:57 pm)
Wow, Phil, that was my idea too.

David, I responded to your thread and basically said how to do a script based raycast solution.




Anyway, Phil, about %this and raycasting ( I assume you mean %this, right?) .

Yes %this USUALLY means player but sometimes they use it for the datablock, since it's the datablock's member function, not the player's.

Just make sure you are getting the player and then put the player object as the 4th parameter.


----

Oh yeah, about swords, you meantioned it got killed "in short order".


Back in T2 I made a "beam sword", basically a targeting laser with length of 8 that would raycast down the length. You had to swing it around (lol) to do real damage, and it was pretty cool because it worked like a lance too, leading to jousting battles. Anyway, a little "issue" I had was that I wanted the damage to not be based on how much time the sword was in them, since this isn't realistic. The basic concept to getting around this is to make sure you stop hitting that player before you apply hit damage again. Basically, wait for the blade to exit thier body.
#5
10/10/2002 (4:15 pm)
Max.. yeah, just do an edge detection about the collision state (so that it only does damage when your last collision wasnt a hit and the current is a hit).

I was really wondering about the scriptThis item that appears in most Console::executef callbacks. I assumed it was the calling object that was calling the script (in this case a shapebase object which happened to be my player).

I passed my scriptThis as %player into the raycast as the last parameter (which I believe is an object to NOT raycast collide with), but that doesnt seem to work.

I'll spend a bit more time with it this weekend. Do a few traces and see whats occurring.

Phil.
#6
10/10/2002 (4:17 pm)
Good idea.

I have no idea waht scriptThis is actually, so, oops.

I will confirm the statement that the 4th parameter is the excluded object, regardless of mask.
#7
10/13/2002 (2:42 am)
Ok, went digging a little more, turns out I had missed a parameter in my callback script function. That meant I was using the wrong variables for the wrong items (%slot was actually the scriptThis()).

So anyway, I fixed the callback function, now it seems to be getting passed a player which I pass to my raycast. Unfortunately this player and the %target I get back from the raycast dont have the same ID's.

Which leaves me thinking I'm not taking the network into account. I must be doing this "client side" when in fact I need it all done server side.

Does the animation actually get done on the server? if thats not the case, then this animation must be getting done on the client. How do I map a client id to a server id for a script function callback??

I'll check the fixed script function in, (although its not fixed yet).

Phil.
#8
08/11/2008 (4:46 am)
I have a question about sword collisions, I'm hoping you can help me with:

How do I set up a sword to collide with barrels, boulders and other objects? I have set up the melee resource from Josh Moore and got that to successfully kill bots. I have also set up the exploding barrels from Ken Finney's Advanced 3D Game Programming All in One book and they explode just fine when struck with a crossbow bolt. Now, when I strike it with a sword, it doesn't explode, though my sword can kill bots. I suspect it doesn't work with the barrels because I have no SwordProjectile::onCollision method set up in sword.cs. So I tried to set that up using CrossbowProjectile::onCollision as an example and still saw no collisions or explosions. I really want to figure this out because I want to be able to get the sword to do more than just kill bots. I want to cut tall grass, knock rigidshapes around, like my rollable boulders, etc...


Does anyone have any ideas?