2 weopons...

i have a game it’s in games works in progress and what not. any way i have a SA-80 as my main gun, i have a M4 that i modeled and i want to use it as well does any one know how too?

Ah, having multiple weapons took me some time to figure out how to implement in my current game, Energy Crisis. First you will need an empty. (Or some object to handle the logic) i called mine, “Weapon Handler”. Make a property, type int, and call it weapon. This will be what handles your weapons. 1 will stand for the first weapon, and 2 for the second. Then use a mouse wheel up/down sensor. You will need one for each, and make sure you set a frame pulse of at least 30. (That would make sure your player cannot switch faster than 1/2 a second.) The actuators to these need to be properties, adding one or subtracting one. Add a property sensor, to detect if the number is zero. then on the actuator set the property to 2. Then do the opposite for 3 and set it to 1. Once you have progressed thus far, you need to add a property sensor, if it is 1. Then have 2 actuators. One to make the first object invisible, and to make the other visible. Then do the opposite for the other weapon.

That should give you a basic weapons switching system with no python. Make sure, that both of your weapons, start out in the scene. This is a simple way, if you had more than 3 or 4 weapons (Energy Crisis has 7) you will want to use Add/End Mesh actuators…

Hope That Helps!

thank you ever such

here was my attempt at multi weapon pick up/change as an example of 1 way to do it with only logic bricks. wsad to move, e to pick up the weapon when you’re near it, 1 and 2(not numpad) to swap between weaps after you pick them up, left mouse button to swing.


weapswap.blend (611 KB)

do you have a tutorial on this

no sorry, i’ve never written a tutorial before and dont have a good enough connection to do a video tut. If you just dig through the example tho it shouldnt be too hard to figure out.

can you write the method on how to change weapons like you did with numbers 1 and 2

yea, when i get home i’ll try to write something out for you, will be a few hours or so.

Ok, I’ll start by saying this isn’t the best way to do this and it isn’t perfect(for example if you wanted to use the mouse wheel to cycle weapons this wouldn’t work without adding some extra properties), but it’s what i came up with one night while droppin’ a major deuce and it seems to work pretty well.

First off, put each of your weapons on a separate layer, and give each weapon it’s own unique object name. in my example they are on layer 3, and named w1 and w2. For every weapon on the separate layer, you need to give them each a few logic bricks.
Always > AND > Parent/Set Parent. on this one you want to turn pulse mode off so that the always sensor only pulses once when it’s added to the scene. Set the parent to be the empty object that I’ll explain later( named “hand” in my example. Next, you’ll need to add your keyboard sensors. in my example, i have 2 weapons, and you use the keys 1 and 2 to swap weapons, so i have a keyboard sensor each weapon, if you had 3 weapons you’d have 3 keyboard sensors(1-3keys). if you had 9 weapons you’d have 9 keyboard sensors(1-9 keys) and so on. How ever many sensors you end up with, connect them all to the same OR controller, and connect the OR controller to an Edit Object/End Object actuator. Every weapon’s logic bricks should look the same.

Next go back to your main scene’s layer. You need to parent an empty to your char(the empty i mentioned earlier), in the position where your weapon needs to be. In my example file i named it “hand”. Give it a keyboard > AND > Edit Object/Add Object modifier. again you need one of these for every weapon you have, setting the keyboard sensors to 1-X keys, where X = number of weaps you have. and on each separate add object actuator, you put the unique name of each weapon.

That’s the basics, every time you hit the appropriate key, it will delete the current weapon, and add the new one. my example has some other crap that wont let you “equip” the weapon until you pick it up, which just takes a few more logic bricks and some properties, but i’m tired of typing now so you can look at it and figure it out yourself or not use it :smiley:

thanks a lot for that.

i’ll credit you in the game.

I guess you already found a method to use, but this might help someone else viewing this thread. For weapon switching, first decide how many weapons the player can have at one time (let’s just say 2 for now.) So make two integer properties, named Weapon1 and Weapon2. Now make another integer property called WeaponSelect. Set up logic bricks to change this third property between 1 and 2 (or however many weapons you have). Now you need to know how many weapons are in your game, and assign each one a number. So, let’s say the SA-80 is 1 and the M4 is 2. If you want to start out with these weapons, have the Weapon1 property be 1, and Weapon2 be 2. Now the logic becomes a little more complex. Using property sensors (or better, python), get the value of WeaponSelect to see which weapon slot you are using. Then, get the value of that slot, to know which gun you are holding. So: Property WeaponSelect Equal To 1 and Weapon1 Equal To 1 > AND > (display SA-80). This works with logic bricks, but can become a hassle if you have a lot of weapons, so I recommend Python instead. With this method, you can simply change the value of the Weapon1 and Weapon2 properties for when you swap out guns. Yes, properties are good to know how to use.