- Home /
Simulate 'Child' Effect by Script
OK so I am currently working on multiplayer of my game. I have added a multiplayer 'gun' and would like to set this prefab a child of the player parent WITHOUT ACTUALLY SETTING IT AS A PARENT. So what I'd need to do is somehow 'simulate' the child-parent relationship without setting the parent. I've tried setting the position & eulerAngles to the parent counterpart, but of course the child-parent relationship is way more complicated. For instance, in my script where I just set the position & eulerAngles = the parent, the position will move with the parent and so does the rotation, but since my weapon 'sticks' out a bit, the rotation is messed up. It is hard to explain, but I will provide a few images for the sake of explanation.
So here is an image of before turning with the parent-child simulation, the smaller gun is the example here. The larger weapon with the arms are just there for a reference.
Here is an image of after I turn slightly to the right:
So as you can see, the weapon turns accordingly to its parent, but it doesn't REALLY simulate the parent-child relation. Any help is appreciated.
Thanks in advance, william9518
Answer by william9518 · Aug 31, 2013 at 12:41 AM
Ugh I fixed it by not doing it at all and revamping the whole system.
Answer by Joyrider · Aug 15, 2013 at 08:13 PM
you could create a dummy that has everything the same as the fake parent, and make your gun a child of that one...
This should make your gun behave just as if it was the fakeParent's child. His local space would be identical than if he really was a child of that object. And modification of the parent would have the same effect as the fakeParent would have.
Don't know if that would be an option for you?
No I cannot use it as an option. I CANNOT set a parent for the gun, I can only use some substitute that may simulate it. Thanks anyway.
Well, maybe you can take it the other way around. Create a dummy child (not child of the gun, but of your want-to-be gun parent) that has the usual position of the gun, and have that child assigns it's parameters to the gun.
Doesn't work. Is there not a way to simulate being a child?
How do you mean.. it doesn't work? what did you do? and what does not work?
And sure, you can simulate... Let's say your it-can't-be-my-gun's-parent is your character. if you know how your gun's local matrix would be like if it was the character's child, you can multiply that character's $$anonymous$$atrix with the local matrix you'd want. Plus some functions allow you to indicate according to what reference you want to apply your movement. So moving your gun with your character as a reference shouldn't be a problem. Having your gun move according to your character's movement can sometimes be a little more tricky.
But 3D is all about math, so you just have to get a little bit more into it.
By 'it doesn't work', I mean I'm doing this in multiplayer. I only set the gun in local, and display it in multiplayer. So only for myself will the dummy parenting work, but for other people it won't. So what I mean is I CANNOT set any parenting for a network, but I can use the networkView for position updating. So any dummy or ANY solution that requires parenting will not work. And about the math, could you tell me more? :3
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Parent object to child of another? 1 Answer
Why is the order of parent and child different depending on where you select them? 1 Answer
Parenting Transforms, Must (still) Set Parent at 0,0,0 ? 1 Answer
Can I add a parent to all the children in an animation tree structure ? 0 Answers