YouGroove Posted March 18, 2013 Share Posted March 18, 2013 With Lua i would want to access directly at the player without collision or camera stuff. Is it a way , something like this : World.getEntity("Player") ? I just want a weapon to find the player and attach to it. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
beo6 Posted March 19, 2013 Share Posted March 19, 2013 untested but basicly just stolen from the GoblinAI: Script.sightRadius = 10--float function FindPlayerInAABBDoCallback(entity,extra) if extra~=entity then if entity.player~=nil then -- do something with entity.player end end end function Script:UpdatePhysics() local position = self.entity:GetPosition(true) local aabb = AABB() aabb.min.x=position.x-self.sightRadius aabb.min.y=position.y-self.sightRadius aabb.min.z=position.z-self.sightRadius aabb.max.x=position.x+self.sightRadius aabb.max.y=position.y+self.sightRadius aabb.max.z=position.z+self.sightRadius aabb:Update() self.entity.world:ForEachEntityInAABBDo(aabb,"FindPlayerInAABBDoCallback",self.entity) end Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 I just needed to access the first entity i find by name. I know for AABB collision, but it's not that feature i wanted. In fact by code i just wanted to program : 1) get entity with this name "Player" (whenever it is located even if not in camera view, even if it don't collide with anything) 2) attach a weapon to it Indeed i can use AABB , a big super cube and just find the good entity name, but i don't knwo if it is super optimized and why not having a simple function ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted March 19, 2013 Share Posted March 19, 2013 This would only get entities in a range around the entity. http://www.leadwerks...eference/world/ Shows a list called entities. Try looping through: App.world.entities maybe? Not sure if this holds true for Lua or not. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/world/worldforeachvisibleentitydo-r506 This would loop through all entities but might not be what you want because it calls another function for each one which but would be out of the scope of where you are calling. You could pass self as the extra parameter though to get access from within this callback. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 local aabb = AABB(-10,-5,-5,0,5,5) --We're going to pass a Vec3 to the callback in the extra parameter local v = Vec3(1,0,0) self.context:SetBlendMode(Blend.Alpha) --Execute the callback for all entities that intersect the bounding box. self.world:ForEachVisibleEntityDo(self.camera,"Callback",self.context) ********************************************* What is AABB for what ? local V : for what to do ? I don't see them to be used ? What is callback for each entity ? What function ? from a script ? Well , i'll have to make player as global in some way to access it's properties like position, rotation. It was to attach weapons, but it's useless as Bones functions don't exist actually in Leadwerks 3. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted March 19, 2013 Share Posted March 19, 2013 I think you can access the bones in your model hierarchy, perhaps directly by name. Try something like: self.entity.bone1.bone2.etc and it would be treated like any other entity where you can :GetPosition(), etc. Note bone1, bone2 is whatever you named your bones in your model hierarchy. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 i don't think it will wrk, we should have some getBone() functions. And i have bone names like : "bone.001" etc ... so it won't work. But i'll rename one and give it a try. How does it workson LE 2 ? Perhaps LE2 never had bones attaching functions ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted March 19, 2013 Share Posted March 19, 2013 bones are just entities like any other. In LE2 they were children of the main entity if I recall correctly and you would call GetChild(entity, number). Once you had the bone you could do anything you could to a normal entity. Rotate it, move it, etc. That's why I'm thinking you can just access the bones directly. You notice that when you put a model into your scene it gives you a tree view of the bone hierarchy. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 yes i see them. I'll had to figure how to acces them by code, i'll try that Getchild() function. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted March 19, 2013 Share Posted March 19, 2013 I'm thinking that won't work. I don't have time right now but I'd try self.entity.bonename.bonename like that instead, but yes if you have dots in your bone names you'd have to change that. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 Rick : HOW CAN I THANK YOU ? SO MUCH ? ? Attaching code on LE 3 Working (cube attached to the leg) I don't have put rotation , to keep weapon well rotated,, but i'll do that in some next code. I tested rotation of bones in the same way by code works also. But caus of animationManager it shows and works only at beginning of animation. ***************** The attaching code debut : function Script:Start() model = Model:Load("Models/other/box.mdl") end attaching code : function Script:UpdatePhysics() ... local child = self.entity:FindChild("Bone.004") local childPos =child:GetPosition(true) model:SetPosition(childPos.x,childPos.y,childPos.z) end For finding some entity NPC by name i think perhaps we can do it by using the world entity and use FindChild ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 It reamins getRotation for child bone and SetRotation to weapon. i'm playing with true and false argument values for both. But strange it'w weird actually, it comes from code i think. Perhaps i'll make weapons placed at the right bone place in Blender with the model character in edit mode before exporting. I think it wll help. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted March 19, 2013 Author Share Posted March 19, 2013 Anyone has some code rotation to have weapon aligned to bone always ? (I'll retry to see if i can succed ?) Quote Stop toying and make games 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.