Jump to content

Pick detection


YouGroove
 Share

Recommended Posts

HI,

 

I have two points with debug spheres , i use a pick and an entity barell with a mass and empty script don't get detected by the ray. It is normal ?

 


self.entity:SetPickMode(0)
 local pickinfo=PickInfo()


 local p0 = self.entity:GetPosition(true)
 p0.y = p0.y + 3     
 local p1 = p0
 p1.y = p1.y - 3  

 if self.entity.world:Pick(p0,p1, pickinfo, 0,true) then  
       self.debug="Raycast HIT COLLISION"    
 end         

 

 

Any idea ?

Stop toying and make games

Link to comment
Share on other sites

Yes, because the player entity is casting the raycast so i coded :

self.entity:SetPickMode(0)

 

This way the player that is casting the ray form it's center won't be taken in consideration for collision etection.

 

I must have something wrong elsewhere ? , but the ray should detect BSP floor or walls ?

Stop toying and make games

Link to comment
Share on other sites

You are aware, that your ray goes into y-direction, which is upwards? I think you rather meant to edit z, not y (as anything with a mass won't stay above you for long ;) ) Also these are global coordinates, so you would probably want to move the points along forward direction, not along a constant axis.

Link to comment
Share on other sites

Yes, it is not what is doing the code ?

The ray starts at p0 that is player center that is foots , i added 3 in Y to have it start just above hear of player model.

And the ray ends at p1 that is p0 with y-3 , that is foots of the player.

I had spheres debug to see the ray start and end position on 3D space and landing on a barrel entity it didn't detectd anything. ray.jpg

Stop toying and make games

Link to comment
Share on other sites

Can you try this?

-- disable model picking
self.entity:SetPickMode(0)

local world = World:GetCurrent()
local pickinfo = PickInfo()
local pivotPos = self.entity:GetPosition()
local rayStart = Vec3(pivotPos.x, pivotPos.y+1, pivotPos.z)
local rayEnd = Vec3(rayStart.x, rayStart.y-50, rayStart.z)
local pickSize = 0
if (world:Pick(rayStart,rayEnd,pickinfo,pickSize,true,Collision.Prop)) then
 local pickentity = pickinfo.entity
end
-- reenable model picking
self.entity:SetPickMode(Entity.SpherePick)

 

If that does not work try to set the pickSize higher.

Link to comment
Share on other sites

  • 2 weeks later...

I have no results and i don't understand if i use it well or not ?

I have a sphere to visualize the ray end and it is okay, and i use pick like that :

world:Pick(rayStart,rayEnd,pickinfo,pickSize,true)

I put true so it returns the first intersection collision only, and no last parameter to return any kind of collision.

 

 

function Script:RaycastPlayer()

-- disable model picking
self.entity:SetPickMode(0)

local world = World:GetCurrent()
local pickinfo = PickInfo()
local pickSize = 0

local rayStart = self.entity:GetPosition(true)

local pivot = self.entity:FindChild("ray")
local rayEnd = pivot:GetPosition(true)

self.debugSphere:SetPosition(rayEnd,true)

if (world:Pick(rayStart,rayEnd,pickinfo,pickSize,true)) then

local pickentity = pickinfo.entity
if pickentity ~= nil and pickentity.id == 1 then
return true
end

end
-- reenable model picking
self.entity:SetPickMode(Entity.SpherePick)

return false



end

Stop toying and make games

Link to comment
Share on other sites

I would also like to debug on entities that are not associated with camera and that are using Raycast and a real 3D line is possible.

 

Anyway i could debug better with your method, but the raycast passes through BSP , i would expect the ray to return the first collision, and when it's BSP that is first collision , the Pick should not find the player character then.

I just need les theoric tutorials and more gameplay practical examples laugh.png

Stop toying and make games

Link to comment
Share on other sites

The main problem i have is the ray, it detects the player, but it detects the player throught BSP walls ?

 

What means that in the doc of Pick()

  • closest: if set to true, the closest intersection will be found, otherwise the operation will return as soon as a single intersection is found.

It's not very clear.

True means one collision only is returned, the first closest collision that happens

False means all collisions will be returned

Stop toying and make games

Link to comment
Share on other sites

I found a working solution :

http://www.leadwerks.com/werkspace/topic/11840-animation-models-tutorial-request/page__hl__tutorial

 

 

function Script:RaycastPlayer2()

-- disable model picking
self.entity:SetPickMode(0)
local world = World:GetCurrent()
local pi = PickInfo()
if (world:Pick(self.entity:GetPosition(true), self.target:GetPosition(true), pi, 0, true)) == false then 

return 0 

end

-- did we hit our target?
if pi.entity == self.target then 
 return 1 

 end

-- we hit something else
return 2


end 

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