Game Development Community

Throwing items

by Kirby Frugia · in General Discussion · 10/04/2002 (8:51 am) · 5 replies

I just have a quick newbie question. I want to be able to throw an item. I see that there is an onThrow function in item.cs, but how do we map a keyboard (or mouse) event to this? For example, I want this to be called when I right-click on the mouse.

Thanks in advance.

#1
10/09/2002 (11:53 am)
It's not quite clear what you mean by the word "throw"...

(I sound like a politician...)

The onThrow() function you are talking about is to drop an item that is in your inventory. This takes an item that is in your inventory and drops it.

There is no code currently in the game to throw an object like a knife or handaxe at another player. However, you could modify the weapon system by adding a knife or handaxe as a projectile weapon. To do this you would have to create three modeled objects. (You might be able to get away with two or even one in some cases by reusing a single model). The first would be a new weapon like a knife or handaxe that would be in the player's hand when he is running. The second would be a some type of weapon projectile - this would be the weapon in the air when it is thrown. You would also need an "ammo" form of the knife or handaxe so you could pick it up off the ground. It might be a belf of throwing knives or handaxes. You would need to create an animation to throw the item at the intended target and you would have to tie the animation to the fire mechanism "mouseFire" button (look for default.bind.cs) to replace the traditional gun fire.

By copying and modifying the weapon code for the crossbow or rifle (look for crossbow.cs or rifle.cs) you could come up with a reasonable weapon that could be thrown at an opponent. You would have to remove a lot of the particle effects and such (unless you want to hurl fiery axes...) An entire tutorial would have to be written to explain exactly how to do this.... hmmm. But I'm sure you will get the idea when you look over the appropriate .cs files.

The third possibility is that you want to pickup objects in game like chairs and statues and be able to hurl them... This is currently not possible with the existing code. You would have to write it. Of course you could create a statue projectile - but that's going just a bit far...

Hope that helps.
#2
10/09/2002 (2:11 pm)
Thanks for your help. I was able to modify the weapon code so that I could simulate throwing a weapon (by having the "ammo" be the same model as the weapon). However, I want the weapon to persist in the world once it is thrown. I think I'll need to modify the source code for this (which is what I figured I would have to do anyway) and make a throwable object type class. Hopefully I should get a good start from the existing code.

Thanks again,
Kirby
#3
10/09/2002 (5:10 pm)
just use the same image for the weapon and the ammo so that when you pick it up it looks like a knife in your hand, then the projectile is just the same image
#4
10/09/2002 (5:32 pm)
Robert - This is essentially what I've done so far. What I'd like to be able to do now is have what is "thrown" stay in the world. If it is ammo, it times out and disappears (or it hits something and disappears). I think I may have to go into the engine code to figure this one out.

Thanks
#5
10/11/2002 (3:56 pm)
i don't think you have to go into the engine. just find the part of the script that deals with when projectiles hit things like walls and rocks. When they hit the wall or rock, spawn a new knife where it hit.