How to make attachable/detachable parts in a mesh (Using BindToActor)

The BindToActor fuction (CTVActor class) is one of the easiest and fastest methods to achieve attachable and/or detachable parts for an Actor class.

I’ll go straight forward for a very explanatory example. How to attach a sword and a head to a mesh!

Our main mesh doesn’t have a head or a weapon attached to it. We’ll fix that :p

First, you need to add a bone to the head and the sword file named Head and RightHand (for eg). Save and export as static TVA. Only needed bones have to be added. For our example, (Head and Sword) each mesh needs only to have one bone.

The Warrior MUST have bones called Head and RightHand (exactly the same as the Sword and the head bones).

Then in your application you need to declare and load all actors (Body, Head and Sword).

'INITIALIZATION OF OBJECTS (ACTORS)
 
Public Body = Scene.CreateActor("Body")
Public Head = Scene.CreateActor("Head")
Public Sword = Scene.CreateActor("Sword")
 
'LOADING FILES
 
Body.LoadTVA("C:\AppPath\Body_file.tva")
Body.LoadTVA("C:\AppPath\Head_file.tva")
Body.LoadTVA("C:\AppPath\Sword_file.tva")
 
'Specify all what you need for your actors (Materials, Textures....etc) as usual.

Finally, just use the “magic trick” (Binding Head and Sword to the Actor, in that order).

Head.BindToActor(Body)
Sword.BindToActor(Body)

And it’s done! The Head and Sword will be automatically rotated and moved with the main actor.

The Head and the Sword are good examples for understanding, then you can apply this method for anything you want (Shield, armor, hat, helmet, clothes, armors, hands, legs, etc...)

As you can see in that picture, we can combine different meshes to have non identical actorss in-game (in this pic, Shields, Heads or Helmets, Weapons are different, the body is the same :p)

Peace.

 
tutorialsarticlesandexamples/how_to_make_attachable_or_detachable_parts_in_a_mesh.txt · Last modified: 2013/11/22 13:32