Search the Community
Showing results for tags 'pickinfo'.
-
Hi everyone, I'm currently encountering an issue with a Pick operation in my Lua code and I'm hoping someone can help me figure out what I'm missing. Here's the context: I have a player controller, which is essentially a pivot that creates a light and a camera. The player controller doesn't involve any movement, the mouse position on the screen simply influences the camera rotation. I also have an enemy that randomly spawns and passes in front of the light, down a corridor. I want to check two things - if the light is on, and if the enemy crosses the light's path. If both conditions are met, I want to call a method from the player script to the enemy script. Here's the relevant part of my player controller code which handles the light being on and the Pick operation: function Script:UpdateWorld() [...] if not self.flashlight:Hidden() then local pickInfo = PickInfo() local i**** = self.entity.world:Pick( self.entity:GetPosition(), self.lightRayEnd:GetPosition(), pickInfo, .25, false, Collision.Character ) if i**** and pickInfo.entity:GetKeyValue("classname") == "npc_nurse" then pickInfo.entity.script:SetPlayerIsShiningLight() end end end The flashlight check works as expected. However, I'm having trouble with the Pick method. It seems to correctly pick up the enemy when it crosses the ray's path. But it also appears to pick up another entity. I've simplified my map to include only a floor for the enemy to walk on and the basic set-up for the player controller. I've confirmed that the KeyValue is being correctly set in the enemy script (in the Start method), and that the collision is set to Character. Through debugging (I've removed all the console debug statements from the code above for clarity), I found that when I test for the pick position, it returns 0,0,0. To make sure I wasn't missing something in my calculations, I created another pivot to mark the end of the raycast (self.lightRayEnd). Does anyone have any idea what I could be doing wrong, or what might be causing this issue? I appreciate any input or suggestions. Thanks!
-
I first noticed this on a mesh generated using the Surface class but have also checked it against the default teapot model. The result of a pick ( World:Pick() ) will always have triangle 0 instead of whatever the correct triangle id is. I am using the latest Steam version of Leadwerks and my project is up to date. I'll try to put together a simple demonstration scene but it should be pretty easy for anyone to confirm this. It's pretty much as simple as: local Picked = PickInfo() local Hit = World:GetCurrent():Pick(StartPos,EndPos,Picked,0,true) --true for getting the 'nearest' hit --make sure StartPos and EndPos go through a model print(Picked.triangle) --always 0
-
Forgive me if this is a silly question, but my previous experience with collision normals is as follows: collision on X should return Vec3(1,0,0) collision on -X should return Vec3(-1,0,0) collision on Y should return Vec3(0,1,0) collision on -Y should return Vec3(0,-1,0) collision on Z should return Vec3(0,0,1) collision on -Z should return Vec3(0,0,-1) Leadwerks pickinfo.normal returns a fraction depending on where on a face the collision occurs. Is pickinfo.face the "normal" function I'm used to, and maybe pickinfo.normal is describing the hit point? If this is the case, how do you use pickinfo.face, I couldn't find much documentation on it? Thanks!
-
I'm familiarizing myself with Leadwerks and so I have a simple test map that lets me place block prefabs like Minecraft. How can I retrieve the name from a pickinfo.entity? I tried the following, but it throws an error in Print in the window:MouseDown(1) check: (argument #3 is 'string'; '[no object]' expected.) function Script:UpdateWorld() if block == nil then block = Prefab:Load("Prefabs/CM/Block.pfb") block:SetKeyValue("name","Block") block:SetCollisionType(Collision.Prop) end local pickinfo = PickInfo() local mousePos = window:GetMousePosition() if (self.player.script.camera:Pick(mousePos.x, mousePos.y, pickinfo, pickradius, true)) then block:SetPosition(Vec3(math.floor(pickinfo.position.x), math.floor(pickinfo.position.y), math.floor(pickinfo.position.z)) + Vec3(pickinfo.normal.x, pickinfo.normal.y/2, pickinfo.normal.z)) end if window:MouseDown(2) then -- Place the block block = nil end if window:MouseDown(1) then -- Delete the block if pickinfo ~= nil then if pickinfo.entity ~= nil then System:Print(pickinfo.entity:GetKeyValue("name")) end --if pickinfo.entity:GetKeyValue("Name") == "Block" then -- pickinfo.entity:Release() --end end end end The other issue I'm having is that the placed prefabs have no physics collision. Thanks, Mike