make object parent in realtime engine

(S_W) #1

Is it possible to add an object in the realtime engine and to make it parent to another object? For example: I have a player and when I press a button a weapon is added, which is made parent to the player.
Does anybody know a solution to this problem?
Thank you very much :smiley:

(Ben) #2

-Try with Replace Mesh.

(S_W) #3

well, but that doesn’t work neither with the armature nor with its mesh.

(saluk) #4

The only way I would know to actually do a makeParent() type operation in python would be to write your own. Not easy, but doable. It just takes some annoying trig, which I am bad at :slight_smile:

Here are the two hacks I have used:

  1. Use an empty as the actual child, and co0nstantly set the objects position to the position of the empty. (I used this approach in pooland, for flexibility).
    Upside: Flexibe
    Downside: There is a bit of lag when the object moves, so there is just the tiniest bit of delay as the object moves. Could be a good thing depending on what you want. It could make turning seem a bit more realistic. But It’s generally a downside.

  2. Have all the guns already set up and parented, but give them size ipos. At frame 1 their size would be 1.0, at frame 2 set the size to 0.0. Then, just use the ipo command to set it to the appropriate frame. When you switch weapons, set the old guns frame to 2, and the new guns frame to 1. I used this approach in soldier down.
    Upside: Fairly easy to do
    Downside: Not flexible, uses a lot of objects which can slow down blender - even though the renderer isn’t rendering all the guns, the object engine still has to manage all of the gun objects

(theeth) #5

Wouldn’t it work with Layer IPO too?


(S_W) #6

Well, I made such a script already, but it didn’t look good with the weapons because of this time delay. I’ll try the other method as well, but I have five weapons with about 900 faces each…

I’m not sure whether this works in the gameengine, but I’ll give it try!

Thank you both for your help! :slight_smile:

(saluk) #7

As far as I can tell, layer ipo doesn’t work in the game engine. I think the game engine only has one layer, as soon as you press play, it compiles all active scenes into the game engine, and compiles objects which are in invisible layers into the library for use with add object. I could be wrong about it, but I cant seem to make layer ipo work :frowning:

I don’t know how to get rid of that lag, but there’s GOT to be a way. Oh well, I think the size method would work the best, for now, if you start seeing too much slowdown I dont know what to tell you :frowning:

I think replace mesh WILL work, if you set everything up right and are very careful with it. Seting the mesh to replace with from python doesnt work though, so you’d have to set a prop and use logic bricks to choose the mesh that way.

Hope you can work it out!