Inventory

In my game, you will be able to switch between weapons that you have picked up. I have a vague idea of how to do this, but I’m sure I could get ten thousand posts about how to do it better. So here’s my idea: I have variables to know if they’ve been picked up, then swap them through layers to equip them (which I don’t know how to do, so even if you say “Scrap that whole idea and do it this way!” that would be good to know for future reference.) Thanks!

If no one can help, is there at least a good link someone might know about?

Maybe using states? Search for a tutorial in the forums, since it’s new there are several that are good.

You asked for a link and so you shall receive:
http://theboomshelter.com/itute.html

That download doesn’t work. I had already seen it and was going to base my idea off of that, but do it better and right. I’ll check the forums for a state tutorial.

Hm, sorry about a dodgy tutorial then.
Instead of swapping them through layers you could set them visible or invisible using .setVisible(TRUE or FALSE)

But then for Mele weapons, a collision sensor wouldn’t suffice.

Are states the same thing as Layers? If not, how do they differ?

States are different to layers, there are some tutorials/doccumentation about states on this thread
http://blenderartists.org/forum/showthread.php?t=133975

im still racking my brain with finding a good way of doing close combat weapons in the BGE. I’ve tried lots of things and thought of lots of things but none of them are really satisfactory.
As you said, a collision would not work unless all your enemies were ragdolls and i got a ray sensor method half working << where the ray gets the hit object and tells it that it has been hit by said weapon and then the hit object reacts in a certain way ( it was working a second ago but then i went to do something else and now it won’t allow me to change properties on the hit object romotely ) >> but the problem is you need many rays projected across the blade or edge of the weapon and although this works for a stationary weapon, having your character hold it is another story…
There was a time when you could parent objects to bones and have the entire thing move including the object center rather than just moving the verticies. This allowed you to parent empties to bones and would make swinging a weapon quite easy. but when they revammped the rigging system that dissapeared (or i can’t find it)
I’m really not sure how it is possible but am currently searching for a solution.

for weapons, using visibility for the models in a good idea. to keep a log of the items, I suggest you use a list.

allright so here is the best method that i have been able to pull off:
for the inventory there are tonnes of ways you can do it but usually what people do is they have a bunch of items that can be equipped parented to the character and when they aren’t currently in use you just set them to be invisble. This works but is perhaps a bit more hard on the processor cause the object still technically is THERE its just invisible.

Alternatively, you can have an inventory that is comprised of a list of objects and they become instantiated << ie: add Object listOfObjects[index] >> when they are equipped and you use << end object >> when they are un-equipped. You can easily add objects to the list (such as if your character picks up a new weapon). Each weapon must be parented to the character or to an object parented to the character (or if that doesn’t work, fake-parent the objects by copying position)

Now the main issue people (mainly me) are having with getting your character to hold weapons and items is that there is no way to get your weapon to move with the character AND register hits against enemies in a very good way. What I mean is that the best thing to do is to use rays that detect contact with an enemies ‘hit-box’ and do a multitude of things with that information but you can’t do that very easily because you can’t parent Object - to -Bone in the new blender versions.

So I embarked on a way to solve this problem…
My solution is that you create an object that consists of a small bundle of verticies where you want your character to hold the weapon. This object will be parented and deforming to your character’s rig. You then get your weapon and tell it to find the positional data of one of the verts in that bundle of verticies and to snap to it (make sure you do a conversion from local to global coordinates). This will allow the actual weapon object to follow the verticies rather than just the weapon mesh (anything parented to the weapon such as a ray sensor also follows).
— So is that it? no not quite. It will follow but it won’t copy any orientation of the arm that is swinging the weapon! What I did is that when the animation was preformed by the arm, I have the weapon preform an ipo rotation in-tandem. Now if you want to do weapon combos it gets a bit complicated but it is possible by simply adding different rotation sections to the ipo with small gaps in-between (too bad you can’t add actions like you can with poses).

things to remember is that you can use ray.getHitObject() to access objects that the ray makes contact with and you should try to set it so that a hit is only registered if the weapon is attacking (there is a difference between simply being equiped and actually attacking with the weapon but the ray won’t know that difference unless you tell it).

So if thats a bit much to handle sorry but i felt that it would be useful for anyone else who wants to attempt something similar. Right now i am embarking on further complicating everything by having both weapon combos and a different reaction from the hit Object depending on the direction and location of the attack.
I’m sure i missed things and probably only resulted in make everyone more confused but hey thats what makes blender fun.