- Home /
Reposition objects during character customization
So I have a robot that can be customized.
Each part of the robot (Head, Torso, Arms, Legs) can be changed with different shapes and forms.
The robot looks like this (I'm using Unity objects for now) :
Let's say the user changes the Torso and decides to put a cube torso instead of the rectangular one, then it would look something like this :
Now in both cases, the parts aren't really joined together, you can clearly see space between the head and the torso, the arms and torso, the legs and torso.
Regardless of the shape and form the user chooses, the end result should look like this img link without any spaces.
Each part has its own collider (Box/Sphere/Cylinder), so I was thinking of moving a part (ie: Head) downwards until it collides with the Torso so that it sits on top of the torso removing unwanted space.
What do you think of this approach? Is there anything simpler?
Answer by Hellium · Jan 13, 2017 at 10:07 AM
Using physics may not be a good idea for this purpose I guess.
What I advise you :
Each part of your robot must provide empty gameObjects called "AttachPoints"
Each head must have its attach point at the bottom, the torso must have 5 attach points, ...
Each part of your robot must have a script referencing their attach points
When changing part of the robot (except torso), move the part so that its attach point is attached to the attach point of the torso
For the head, you may have :
this.transform.position = torso.headAttachPoint.position + ( this.transform.position - this.torsoAttachPoint.position ) ;
When changing the torso, move all the parts of the body so their attach points are attached to the attach point of the torso
Thank you for the reply! I am going to try this and will get back to you soon! :D
Ok so I tried your solution and it works!
I modified the torso to see if the solution is going to respond the same way on a different size and it worked too given that the AttachPoint doesn't change position which is the case!
Last question, I assume the formula is roughly the same for the rest of the parts right?
Thanks again!
EDIT: I tried it with the legs and it works too! Same formula different body parts! Thanks! :D