Game Development Community

Weapons

by Santural · in Technical Issues · 04/02/2006 (10:58 am) · 9 replies

So,
In the 3DGPAi1 book it gives you a very good idea as for ranged weapons. Can anyone tell me how would I program a sword or dagger?
Thanks so much. I really don't get the programming so....

Yatrik

#1
04/05/2006 (3:33 am)
I am a TSE Owner, i can't understand what does the transmitDatablock and activateGhosting function done in the Load a mission part, how it is usefull.

Also explain me how does the following script works and where is %this.inv[%data.getName()]; is declared.

function ShapeBase::getInventory(%this,%data)
{
// Return the current inventory amount
return %this.inv[%data.getName()];
}
#2
04/18/2006 (8:31 am)
@ Roshan how can you be a TSE owner if you don't own TGE yet?
#3
04/18/2006 (8:53 am)
Hm, according to his post history he's made two threads in the TSE private forums. So I guess he does have it. It just seems like he has a problem with posting questions in the wrong forums.
#4
04/18/2006 (9:07 am)
@Yatrik

Since Roshan knocked your question out of the unanswered posts I'll answer it.

As far as I know melee combat involves changes to the source code. So you won't be able to do it using the version from Ken's book or the demo.
#5
04/19/2006 (3:43 pm)
You might create an invisible projectile that is fired from the sword while the animation is played. If you could change the maximum distance of this projectile by playing with the gravity effect on it, you may be able to have it fly only 3 to 4 feet. The onCollision function should still work, but you would have to avoid setting up a particle effect for collision with the ground, because, everytime you chop into mid air, the projectile would collide with the ground near your feet.
But Scott is right, you will need to get into the source code for the weapon to do this.
#6
04/19/2006 (5:20 pm)
No, you don't need to do any source code changes. The simplest way is to just make your weapons onFire do a short raycast check instead of using any projectiles.
#7
04/20/2006 (6:24 pm)
Hey, Paul, could you explain the "raycast check" since I am a COMPLETE begginer......gosh I should know that much but I don't....do spare a moment...

Y.
#8
04/20/2006 (6:42 pm)
In your weapons onFire function, youl'd have something like this

//These are the normal values projectiles use
   %muzzleVector = %obj.getMuzzleVector(%slot);
   %muzzlePos = %obj.getMuzzlePoint(%slot);

   //This is the distance we check ahead
   %hitRange = 1;

   //Damage amount
   %hitDamage = 20;
  
   //This gets us the endpoint of the raycast
   %endPos = VectorAdd(%muzzlePos, VectorScale(%muzzleVector, %hitRange));    

   //This is the actual raycast
   %hitTest = ContainerRayCast(%muzzlePos,  %endPos, $TypeMasks::ShapeBaseObjectType, %obj);
    
    //If the raycast hit something...
    if(%hitTest)
    //The first value will be the ID of the object it hit, so damage that
         %hitTest.damage(%obj, getWord(%hitTest, 1) SPC getWord(%hitTest, 2) SPC getWord(%hitTest, 3),
                                      %hitDamage, %this);

This is a very basic crude setup, not what I actually use. Like I have a function that extracts the position from raycast returns, so I don't have to write all those getWords there.

Somethings to note about a raycast. A raycast returns 7 values. First the ID of what it hit (or zero if nothing), the next three being the position where it hit, and the last three being the normal of what it hit. A raycast takes a start and end position for it's first and second parameters, it's third parameter is a typemask, and the fourth allows it to ignore a specific object (the player "firing" it here).

Oh and I think I might be passing different values into the .damage() function than defaults, since mine is modified, but hopefully you can figure that out.
#9
04/21/2006 (3:11 pm)
So....sorry for being so crude, by adding this and "simply" changing the code in my...weapon(cs) file and changing the .dts file.....but then comes the issue of playing a certain animation to a binded key......god I am gaining knowledge.....but knowledge shows it's way to questions!

Y.