Ruki Posted August 29, 2015 Share Posted August 29, 2015 Hi, I've created and rigged a simple model of a cat and I'm trying to attach a simple sword onto its hand in C++ using SetParent(). Whilst this does put the sword into the cat's hand, when the cat animates the sword seems to animate twice as much (or something), so it appears to rotate too much and swing right out of its hand (See video demo below) Video: https://dl.dropboxusercontent.com/u/15579799/LWE/catmodel.avi After the entity is created, I create a sword model and then Parent it to the left hand bone of the cat entity. // Attach sword Model *weaponModel = Model::Load( myMain->pathManager->getPath_Model( "sword" ) ); Entity *handEntity = catEntity->FindChild( "Hand_L" ); // Set Parent weaponModel->SetParent( handEntity ); // Set Position //weaponModel->SetPosition( handEntity->GetPosition() ); //weaponModel->SetRotation( handEntity->GetRotation() ); weaponModel->SetPosition( 0, 0, 0 ); weaponModel->SetRotation( 0, 0, 0 ); I have tried it with both SetPosition/Rotation( handEntity->GetPosition/Rotation() ) and weaponModel->SetPosition/Rotation( 0, 0, 0 ); but they seem to yield the exact same results. I have also tried to attach the Sword to the LowerArm incase my handbone was somehow moving out of whack but it seems to do the same kind of desynced animation. I have also tried to use "SetEntityMatrix" instead of SetPosition/SetRotation and it made the sword distort into a horrible.. horrible thing. weaponModel->SetMatrix( handEntity->GetMatrix() ); Which looks like the attached picture: https://dl.dropboxusercontent.com/u/15579799/LWE/cat.jpg Please help me! I've searched for hours and I can't figure it out I have tried with the weapon having a bone aswell but it didn't seem to change anything Here are the FBX files of the cat and the sword if it helps: https://dl.dropboxusercontent.com/u/15579799/LWE/catmodel.fbx https://dl.dropboxusercontent.com/u/15579799/LWE/sword.fbx Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 29, 2015 Share Posted August 29, 2015 seems to work fine if you set the position and rotation you want for the sword prior to setting the bone as the parent. simpleanimation2.lua: Script.Speed=1.0--float Script.Sequence=0--int function Script:Start() self.hand = self.entity:FindChild("Hand_L") self.sword = Model:Load("Models/sword.mdl") self.sword:SetPosition(self.hand:GetPosition(true),true) self.sword:SetRotation(180,0,0,true) self.sword:SetParent(self.hand,true) end function Script:Draw() local t = Time:GetCurrent() self.entity:SetAnimationFrame(t/100.0*self.Speed,1,self.Sequence) end Quote 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 More sharing options...
Ruki Posted August 29, 2015 Author Share Posted August 29, 2015 Thanks Macklebee, for some reason I'm still not achieving it. I followed your Lua script exactly but in C++: // Create entity data workingEntityPointer->LWEntity = Model::Load( myMain->pathManager->getPath_Model( "catmodel" ) ); workingEntityPointer->LWEntity->SetMass( 1 ); workingEntityPointer->LWEntity->SetPhysicsMode( Entity::CharacterPhysics ); // Set Collision workingEntityPointer->LWEntity->SetCollisionType( Collision::Character ); // Attach sword Entity *handEntity = workingEntityPointer->LWEntity->FindChild( "Hand_L" ); Model *weaponModel = Model::Load( myMain->pathManager->getPath_Model( "sword" ) ); weaponModel->SetPosition(handEntity->GetPosition(true),true); weaponModel->SetRotation(180,0,0,true); weaponModel->SetParent(handEntity,true); And then the animation update code: LWEntity->SetAnimationFrame(Time::GetCurrent()/100.0,1,0); But I still get the following result when the cat swings it's arm forward https://dl.dropboxusercontent.com/u/15579799/LWE/cat2.jpg Are you able to send the .mdl's you exported incase it's somehow to do with the way I'm exporting them? I'm using blender's Leadwerks exporter *EDIT* This is now fixed, for some reason when I exported my original file in blender using Leadwerks exporter it caused my issue. But I made a new scene and imported the .FBX file I made from it, THEN exported using the Leadwerks exporter somehow fixed something and now it's working fine! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.