Jump to content

Pick strange interactions


YouGroove
 Share

Recommended Posts

I have a Pick function that is pretty simple

 

It just detects if some entity with teamid = 2 is found using Pick()

 

function Script:Raycast()

       self.entity:SetPickMode(1)

       local p0p = self.p0:GetPosition()
       local p1p = self.p1:GetPosition()

       local world = World:GetCurrent()
       local pi = PickInfo()
       if (world:Pick(p0p , p1p , pi, 0, true)) == false then  
           return 0
        end

       if pi.entity ~= nil and pi.entity.script ~= nil    and pi.entity.script.teamid == 2  then
           return 1
       end     

       return 0

end

 

 

When i call that function for the player , firing anywhere, two mobs droids start to moving to the player and don't stop turning around.

 

function Script:Fire()

   self.upperAnimMgr:SetAnimationSequence("fire", 0.01, 75, 1)

   self.entity:Hide()

               local timediff  = Time:GetCurrent() - self.timer
               if timediff > self.timerRate then
                   self.timer = Time:GetCurrent()
                    local entityPick = self:Raycast()
               end   

   self.entity:Show()
end

 

 

Is Pick triggering events or something on other entities scripts ?

I thaught Pick() was a simple raycast detection with no impact on collisions or gameplay ?

Stop toying and make games

Link to comment
Share on other sites

There is no reason at all.

 

Player raycast

 

function Script:Raycast()

self.entity:SetPickMode(1)

local p0p = self.p0:GetPosition(true)
local p1p = self.p1:GetPosition(true)

local world = World:GetCurrent()
local pi = PickInfo()
if (world:Pick(p0p , p1p , pi, 0, true)) == false then
return 0
end

if pi.entity ~= nil and pi.entity.script ~= nil and pi.entity.script.teamid == 2 then
entityPick.script:decreaseHealth(self.damage)
self.debugSphere3:SetPosition( pi.entity:GetPosition(true),true)
return 1
end

return 0

end

 

Droid called function :

 

function Script:decreaseHealth(amount)
self.health = self.health - amount
if self.health < 0 then
--self.health = 0
self.entity:Release()
end
end

 

the problem is calling that and the droid runs to the player and around him ?

Even if i comment the player line code :

entityPick.script:decreaseHealth(self.damage)

 

I will post a zip example with scripts.

Stop toying and make games

Link to comment
Share on other sites

I made a minimal example and the problem is still here ?

 

How to test :

- put map fil in your map directory

- put folder "ScriptsTPS" in your root directory of your project.

- run the game , left click to fire

 

The mob will start moving and turning around the player when you fire, and it should not move as there is no code on Pick changing any variables of the mob ??

 

 

I found that facing the mob it detects you so it stops moving, but if you only rotate yourself and don't face it , it no more detects you ?

bug.jpg

Maps.zip

Stop toying and make games

Link to comment
Share on other sites

why the player raycast make the mob movig ? as anything in the function calls the mob script function or variables ?

 


function Script:Raycast()
self.entity:SetPickMode(0,true)

local p0p = self.p0:GetPosition(true)
local p1p = self.p1:GetPosition(true)

local world = World:GetCurrent()
local pico = PickInfo()
local hit = world:Pick(p0p , p1p , pico, 0, true)

if hit == true then
--self.debugSphere3:SetPosition( pico.position,true)
end

self.entity:SetPickMode(1)

if pico.entity ~= nil and pico.entity.script ~= nil then
--and pi.entity.script ~= nil and pi.entity.script.teamid == 2
--entityPick.script:decreaseHealth(self.damage)
--self.debugSphere3:SetPosition( pi.entity:GetPosition(true),true)
--self.debugSphere3:SetPosition( pi.position,true)
self.debugSphere3:SetPosition( pico.position,true)

end

return 0

end

I think it is a serious bug.

 

 

Anyone is hot to try the demo ?

Stop toying and make games

Link to comment
Share on other sites

No the target loosed, it's a LE3 bug about scripts. In the game on my map the droid have "player" enitty assigned in the script tab.

 

What is crazy , is just launching a Player Pick() have an impact oin the droid Pick(), because the droid uses Pick() every time.

 

Ok, i just found the problem , when i have this line of code the droid don't find the player no more with raycast :

 

self.entity:SetPickMode(1)

 

If i remove that line, it works.

 

I changed the code to

function Script:Raycast()
self.entity:SetPickMode(0)

local p0p = self.p0:GetPosition(true)
local p1p = self.p1:GetPosition(true)

local world = World:GetCurrent()
local pi = PickInfo()


local picked = world:Pick(p0p , p1p , pi, 0, true)

self.entity:SetPickMode(1)

if picked == false then
return 0
end

if picked == true then
if pi.entity ~= nil and pi.entity.script ~= nil and pi.entity.script.teamid == 2 then
 --entityPick.script:decreaseHealth(self.damage)
 self.debugSphere3:SetPosition( pi.entity:GetPosition(true),true)
 return 1
end
end



return 0

end

 

But using : self.entity:SetPickMode(1)

And the dorid cannot detect the player again.

 

Why Monster AI do two call in Start() function ?

self.entity:SetPickMode(Entity.BoxPick,true)
self.entity:SetPickMode(0,false)

Stop toying and make games

Link to comment
Share on other sites

I'm not sure I follow what's going on here, but I guess it works now? Also, I'm really sorry, but I some things came up and I'm very busy so I can't test it tonight. :(

 

Why Monster AI do two call in Start() function ?

self.entity:SetPickMode(Entity.BoxPick,true)
self.entity:SetPickMode(0,false)

 

I think what this is doing is specifying the pick type for the hitboxes (children) and the actual mesh (parent), and then removes the parent from future pick tests to increase performance. I just think it's easier to do it in two lines than to iterate through all of the children.

Link to comment
Share on other sites

I think what this is doing is specifying the pick type for the hitboxes (children) and the actual mesh (parent), and then removes the parent from future pick tests to increase performance. I just think it's easier to do it in two lines than to iterate through all of the children.

I understand better now, thanks, sometimes when there is no comment it's hard to guess what coders are doing laugh.png

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