Jump to content

Attaching weapons


Skrakle
 Share

Recommended Posts

I'm trying to add a weapon at a specific bone on my character but finding the child using bone name returns nil. I've also tried several other names in the hierarchy.

 

 

local child=self.entity:FindChild("dwarfmale_stand_bone_RFingerPinky");

Link to comment
Share on other sites

Thanks for the video link but it didn't help because i really need to attach it to a specific bone so my sword will follow/rotate correctly when my character walks or takes a swing and i haven't seen anything bone related in the tutorial. I forgot to mention that i'm loading my models in lua instead of placing it in the editor. I did place one so i can find the bone names.

Link to comment
Share on other sites

We would probably need to see your code/model as I just renamed the hand bone on my model to 'dwarfmale_stand_bone_RFingerPinky" and was able to find it and parent a weapon to it with no issues. I suspect maybe a typo somewhere or since maybe 'child' is a local variable, you are trying to access it out of scope?

 

Edit -- and fyi, it appears you have to match capitalization... so make sure the string matches exactly as shown for the bone name.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I copy/pasted the bone name from the editor.

Dwarf model: Dwarf fbx Weapon Weapon

 

entity={};

function App:Start()

entity[0]=LoadModel("Models/Characters/Dwarf/dwarfmale_run.mdl","Char","Randgard",0,0,5.73,0.02,1,Collision.Trigger,Entity.CharacterPhysics,"");
entity[0]:SetScript("Scripts/NPCS/player_character.lua");

weapons[0]=LoadModel("Weapons/axe_1h_hatchet_a_01.mdl","Weapon","Axe",0,0,0,0.02,0,Collision.None,Entity.RigidBodyPhysics,"");

local child=entity[0]:FindChild("dwarfmale_stand_bone_RFingerPinky");
if (child) then
   weapons[0]:SetParent(child);
   weapons[0]:SetMatrix(entity[0]:GetMatrix())
end

end

 

 

bone_name.jpg

Link to comment
Share on other sites

hmmm i think there is a mixup somewhere... you are loading the 'dwarfmale_run' model but you are trying to find the 'dwarfmale_stand_bone'. In the model you posted there are no 'stand_bones' - only 'run_bones'. I am able to find the 'run_bone' no problem...

post-14-0-92519400-1425764140_thumb.jpg

 

I think you are just loading the wrong version of the dwarf in the editor to find the bone you want, but then are loading a different dwarf model via code that doesn't have that naming convention - therefore its not finding the bone...

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

hmmm i think there is a mixup somewhere... you are loading the 'dwarfmale_run' model but you are trying to find the 'dwarfmale_stand_bone'. In the model you posted there are no 'stand_bones' - only 'run_bones'. I am able to find the 'run_bone' no problem...

 

You're absolutely right, I can't believe i didn't notice that!

 

Thanks for noticing!

 

happy_dwarf.png

  • Upvote 2
Link to comment
Share on other sites

  • 2 months later...

My sowrd is too big and needs a rotation.

How to change that in the code ?

 

self.sword = Model:Load("Models/sword.mdl")

local child=self.entity:FindChild("Bone_002_R_002");
if (child) then
self.sword:SetParent(child);
self.sword:SetMatrix(self.entity:GetMatrix())
end

post-3271-0-78747300-1431722560_thumb.jpg

Stop toying and make games

Link to comment
Share on other sites

Got it working without using matrix.

 

self.sword =  Model:Load("Models/sword.mdl") 
local child=self.entity:FindChild("Bone_002_R_002");
if (child) then
  self.sword:SetParent(child);
  local pos = child:GetPosition(true)
  pos.z = pos.z + 1
  pos.x = pos.x - 0.5
  self.sword:SetPosition(pos,true);
  local rot = child:GetRotation(true)
  self.sword:SetRotation(rot,true);
end

post-3271-0-67386500-1431723036_thumb.jpg

  • Upvote 2

Stop toying and make games

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...