burgelkat Posted September 22 Posted September 22 -- Hut an Kopf attachen if self.hat then local head = self.NPC.skeleton:FindBone("mixamorig:Head") or self.NPC.skeleton:FindBone("mixamo:Head") or self.NPC.skeleton:FindBone("Head") if head then self.hat:SetPosition(Vec3(0,0, -0.06), true) self.hat:SetRotation(55,0,0,true) self.hat:Attach(self.NPC, head) Print("Hut attachiert") else Print("Head-Bone nicht gefunden") end end -- Fuß-Offset berechnen local box = self.NPC:GetBounds(BOUNDS_LOCAL) self.footOffset = -box.min.y Bodencheck local pickInfo = model:GetWorld():Pick(agentPos + Vec3(0,1,0), agentPos + Vec3(0,-10,0), 0.0, true) local npcPos = pickInfo and Vec3(agentPos.x, pickInfo.position.y + self.footOffset, agentPos.z) or Vec3(agentPos.x, agentPos.y + self.footOffset, agentPos.z) model:SetPosition(npcPos) I have this in my NPC script. With that my npc walk always at ground and not hover even the ground is not flat. If i attach a hat to the NPC model the hat would not follow the model. The hat is attached at bone. Is it possible that an attached model as a child is not being updated or repositioned accordingly? At first the hat is positioned correctly, but when the NPC moves, the hat floats independently, sometimes above and sometimes below the NPC. Can someone give me a hint, where i should pay attention in the code if i work with attached models like hat or sword, if i work with that code? Quote 1 Quote
Josh Posted September 25 Posted September 25 This example shows an animated character wearing a hat: https://www.leadwerks.com/learn/Entity_Attach?lang=lua 2 Quote Let's build cool stuff and have fun.
Solution burgelkat Posted October 6 Author Solution Posted October 6 Ok, after a few attempts, I realized that it’s better not to work with Pick, especially in Update. That only works if no additional models (like a hat, sword, etc.) are attached. Therefore, only use 'footOffset' once in Start. Then attaching and moving additional models (hat, sword, etc.) works perfectly. Also the NPC Model is at ground and not hoover anymore. -- Beim Start() den Fußpunkt-Offset einmalig setzen self.footOffset = -0.2 -- NavAgent erstellen und an NPC anhängen if navmesh then self.NavAgent = CreateNavAgent(navmesh) local agentPos = self.NavAgent:GetPosition(true) self.NPC:SetRotation(0,-180,0) self.NavAgent:SetRotation(self.entity:GetRotation(true).y) self.NPC:SetPosition(0, self.footOffset, 0) self.NPC:Attach(self.NavAgent) if self.NavAgent then Print("start mit NavAgent") end if not navmesh then Print("kein NavAgent gestartet") end self.NavAgent:SetPosition(self.startPosition) -- Hier die Rotation explizit auf die Start-Rotation setzen self.NPC:SetRotation(self.startRotation) end 2 Quote
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.