Jump to content

[LE3] How to find a specific entity ?


YouGroove
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 ?

Stop toying and make games

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Stop toying and make games

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 blink.pngblink.pngohmy.pngohmy.png ?

Stop toying and make games

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Rick : HOW CAN I THANK YOU ? SO MUCH ? smile.pnghappy.png ?

 

attachingcode.jpg

 

Attaching code on LE 3 Working biggrin.png (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 ?

Stop toying and make games

Link to comment
Share on other sites

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.

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...