Weapon Switch

Blitz3D Forums/Blitz3D Programming/Weapon Switch

wizzlefish(Posted 2005) [#1]
I'm creating an FPS and the entire point of it is for it to be dynamic - so I can create levels on the fly just by editing a simple XML file. It was all going fine until I got to the weapon part. I needed a way to dynamically pick up weapons, and toggle weapons depending on how many you had.

Here is my code so far. "WEAPON_Update()" is called in the main loop.


This code doesn't work, but otherwise, I have no other way to approach the situation.

Any ideas?

Thanks in advance,
No Enemies


jfk EO-11110(Posted 2005) [#2]
I didn't read your code, just let me tell you how I kind of solved it: All possible weapons of the player are loaded at startup, then hide them. Every weapon has its shooting and reloading animations. Switching weapons will become as easy as showing and hiding a weapon. I added a "turn weapon out of view" job that is started as a polling process (fake parallel thread). When the current weapon is turned out of the camera view (some frames later), the current weapon becomes hidden and the wanted gun will unhide. This new current gun starts another polling process that will turn the weapon to the default aiming position. If all these parallel jobs are complete, the player may use the next gun. During switching weapons, they are deactivated.

Of course, instead if turning the guns away/back using some variables and polling jobs, you could also use a simple animation, "turn-mp5-outofview.b3d" or something. By checking the current animation state you could decide when to switch the guns effectively.

I hope this makes sense.


wizzlefish(Posted 2005) [#3]
OK. I think I understand now. I've been going around the problem completely the wrong way.

[EDIT]
OK, I've got the "switching weapons" part - that was easy. Now I need to figure out how to pick up weapons. Each weapon is stored in a type, and I rather it stayed that way, but I guess I could change them to separate entities...but I still need to be able to "pick up" the weapons from the ground, and have them in hand and ready to activate.


Techlord(Posted 2005) [#4]
No Enemies

What type of 'Trigger' System are you using. Triggers are merely boundboxes placed in the level to 'activate' some action when collided with by the player, bot, etc. Do you have something like this.

You could simply create a collision box around weapon so when player collides with it, he instantly picks up the weapon (becomes part of inventory) and ready for use.


wizzlefish(Posted 2005) [#5]
I've got it set so if the player comes within 3 units of the weapon, he picks it up, but since I'm using types, it's hard to make the weapon disappear and appear in the inventory, without using duplicate entities.


Techlord(Posted 2005) [#6]
but since I'm using types, it's hard to make the weapon disappear and appear in the inventory, without using duplicate entities
I'm not quite sure how using types is giving you grief...

Sounds like a collision identification problem to me. Who hit who. How are you detecting collision? How are you identifying the entities in the collision?


octothorpe(Posted 2005) [#7]
I think it's perfectly fair to use separate entities for powerups (the weapons that are waiting on the ground for the player to pick them up) and weapons in the player's inventory. Since the player character's hand might be part of the inventory version of the weapon, it might be preferrable!


wizzlefish(Posted 2005) [#8]
octothorpe: Ok. I guess I will use separate entities.


octothorpe(Posted 2005) [#9]
Oh, and you might find it easier if you keep track of the player's current weapon in a global variable (of type weapon) instead of doing a CameraPick.


wizzlefish(Posted 2005) [#10]
Ok. Thanks. My weapon system should be done in no time.


jfk EO-11110(Posted 2005) [#11]
(what octothorpe said. I use seperate entities too, a high poly version including hand and lower arm for the player, a low poly version to pick up. Picking method could also be a simple "if Entityditance(player,gun) < d"... )


wizzlefish(Posted 2005) [#12]
Yeah. I used EntityDistance in my past FPSes.