Yue Posted April 26 Posted April 26 I am trying to put the case of my character having as reference the spindle of the nape of the neck, but it turns out that when he is falling into the void after a jump the case starts to float above his head, this using attach. Now, if I use SetParent, to attach it to the mesh, whose root bone is in the middle of the legs, when falling the helmet does not move from its position. In such a case I need to position it in the head, in the Neck bone, and I have found a partial solution. function this:UpdateHelmet() helmet:SetPosition(0,0.12,-0.03) helmet:SetRotation(-20,0,0) helmet:Attach(ela,boneNeck) end ... self:UpdateHelmet() -- Run Ok. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 2 Posted May 2 Does this start happening when the player is falling at a fast speed? Does it get worse the faster they are falling? 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted May 2 Author Posted May 2 2 hours ago, Josh said: Does this start happening when the player is falling at a fast speed? Does it get worse the faster they are falling? It happens after a jump, and gets worse when falling into the void. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 2 Posted May 2 13 minutes ago, Yue said: It happens after a jump, and gets worse when falling into the void. Okay, I think the bone attachment code is probably running one frame behind the physics update. I should be able to move the place this happens and it will fix the problem. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted May 14 Author Posted May 14 Lo tengo dentro del bucle, pero sigue al personaje en el hueso de la cabeza, pero va como si fuera un helicóptero helice d eun girando sobre el hueso de la cabeza. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 14 Posted May 14 I thought the problem was that the attached object was trailing one frame behind, but the test case I created shows it working perfectly at high speeds. #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a world auto world = CreateWorld(); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetFov(70); camera->Move(0, 2, -8); //Create light auto light = CreateBoxLight(world); light->SetRotation(45, 35, 0); light->SetRange(-10, 10); //Model by PixelMannen //https://opengameart.org/content/fox-and-shiba auto model = LoadModel(world, "https://github.com/UltraEngine/Documentation/raw/master/Assets/Models/Characters/Fox.glb"); model->SetScale(0.05); model->Animate(1); model->SetRotation(0, -90, 0); auto neck = model->skeleton->FindBone("b_Neck_04"); auto head = model->skeleton->FindBone("b_Head_05"); Vec3 rotation; //Model by alissvetlana //https://sketchfab.com/3d-models/hat-a7f54e87bea94730b4a1827ec1f770df auto hat = LoadModel(world, "https://github.com/UltraEngine/Documentation/raw/master/Assets/Models/Characters/hat.glb"); hat->SetScale(0.025); hat->SetPosition(-0.3, 0.4, 0); hat->Attach(model, head); //Main loop while (window->Closed() == false and window->KeyHit(KEY_ESCAPE) == false) { float move = 0; if (window->KeyDown(KEY_RIGHT)) move += 1; if (window->KeyDown(KEY_LEFT)) move -= 1; model->Translate(move, 0, 0); light->Translate(move, 0, 0); camera->Translate(move, 0, 0); window->SetText(model->position.x); world->Update(); rotation.y = Cos(float(Millisecs()) / 10.0f) * 65.0f; neck->SetRotation(rotation); world->Render(framebuffer); } return 0; } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted May 14 Author Posted May 14 Ok, it's something here as I'm doing things, these weirdos just happen to me. The mesh I load it in a sequence inside a loop, but to make it work for me I have to do this. And it only goes inside the loop. function this:UpdateHelmet() if helmet and boneNeck then helmet:SetPosition(0, 0.12, -0.03) helmet:SetRotation(-20, 0, 0) helmet:Attach(ela,boneNeck) end end function this:UpdteBackpack() if backpack and boneBack then backpack:SetPosition(0, -0.1,0.1) backpack:SetRotation(0, 0, 0) backpack:Attach(ela,boneBack) end end Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 14 Posted May 14 Are you attaching it every frame or just once? Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted May 14 Author Posted May 14 In each frame, so that it does not move when it falls into the void. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 14 Posted May 14 That might be the cause of the problem. Maybe you should just attach it once? Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted May 15 Author Posted May 15 But if I attach it only once, when falling into the void the helmet starts to rise and moves out of the character's position on his head. It is as if the controller is faster. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Yue Posted May 15 Author Posted May 15 I have done this, and it seems to go well, that is to say that for attach to work correctly I have to use it inside the loop so that the case does not fall off when the character is falling. I think maybe that's what makes it attach internally. function this:UpdateHelmet() local posBone = boneNeck:GetPosition(true) local pos = TransformPoint(posBone,ela,nil) helmet:SetPosition(pos,true) local rotBone = boneNeck:GetQuaternion(true) local rot = TransformRotation(rotBone,ela,nil) helmet:SetRotation(rot,true) --if helmet and boneNeck then -- helmet:SetPosition(0, 0, 0) -- helmet:SetRotation(0, 0, 0) -- helmet:Attach(ela,boneNeck) --end end Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 15 Posted May 15 I need a working example I can run in order to test this. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted May 15 Author Posted May 15 I have sent the project by inbox. Ficle Script Lua. Player.lua. function this:UpdateHelmet() local posBone = boneNeck:GetPosition(true) local pos = TransformPoint(posBone,ela,nil) helmet:SetPosition(pos,true) local rotBone = boneNeck:GetQuaternion(true) local rot = TransformRotation(rotBone,ela,nil) helmet:SetRotation(rot,true) --if helmet and boneNeck then -- helmet:SetPosition(0, 0, 0) -- helmet:SetRotation(0, 0, 0) -- helmet:Attach(ela,boneNeck) --end end function this:UpdteBackpack() if backpack and boneBack then backpack:SetPosition(0, -0.1,0.1) backpack:SetRotation(0, 0, 0) backpack:Attach(ela,boneBack) end end on start. self:UpdateHelmet() self:UpdteBackpack() self:UpdteHelmetWaist() On Update. self:UpdateHelmet() self:UpdteBackpack() self:UpdteHelmetWaist() Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted May 15 Posted May 15 I don't know how to make the bug appear. I replaced UpdateHelmet with this code, and it works perfectly: function this:UpdateHelmet() --[[local posBone = boneNeck:GetPosition(true) local pos = TransformPoint(posBone,ela,nil) helmet:SetPosition(pos,true) local rotBone = boneNeck:GetQuaternion(true) local rot = TransformRotation(rotBone,ela,nil) helmet:SetRotation(rot,true)]] if helmet and boneNeck and helmetattached ~= true then Notify("Attaching helmet now") helmetattached = true helmet:SetPosition(0, 0, 0) helmet:SetRotation(0, 0, 0) helmet:Attach(ela,boneNeck) end end It also works fine if you attach the helmet each frame: function this:UpdateHelmet() helmet and boneNeck and helmetattached ~= true then --Notify("Attaching helmet now") --helmetattached = true helmet:SetPosition(0, 0, 0) helmet:SetRotation(0, 0, 0) helmet:Attach(ela,boneNeck) end end Quote My job is to make tools you love, with the features you want, and performance you can't live without.
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.