Jump to content

Pick??


Yue
 Share

Go to solution Solved by macklebee,

Recommended Posts


ventana = Window:Create()
lienzo  = Context:Create( ventana )
mundo   = World:Create()

local sol = DirectionalLight:Create()
sol:SetRotation(90, 0, 0 )

local camara = Camera:Create()




local suelo = Model:Box()

suelo:SetScale(5, 0.2, 5 ) 
suelo:SetPosition( 0, -1, 5 ) 
suelo:SetPickMode(0) 



local punto = Model:Cone()
punto:SetPosition ( 0, 0, 5 ) 
punto:SetColor ( 1, 0, 0 ) 
punto:SetPickMode(0) 



while true do  


if  mundo:Pick(0, 10, 5,0, -10, 5, PickInfo(),1.0, true )  then  



 return false 
end 

	if ventana:Closed() then return false end 


	Time:Update()
	mundo:Update()
	mundo:Render()
	lienzo:Sync()

        
     

end 

Hi, I'm trying to understand lightning, but this doesn't work, from my perspective I create a lightning bolt from the red cone to the ground, and if it collides I expect the program to close. 

What am I doing wrong?
image.thumb.png.870d14d06376c00e165d512f5c729b80.png

 

 

Link to comment
Share on other sites

Okay, I've already removed that command, but it still doesn't work. 

 

ventana = Window:Create()
lienzo  = Context:Create( ventana )
mundo   = World:Create()

local sol = DirectionalLight:Create()
sol:SetRotation(90, 0, 0 )

local camara = Camera:Create()




local suelo = Model:Box()

suelo:SetScale(5, 0.2, 5 ) 
suelo:SetPosition( 0, -1, 5 ) 




local punto = Model:Cone()
punto:SetPosition ( 0, 0, 5 ) 
punto:SetColor ( 1, 0, 0 ) 


local pis = PickInfo()

while true do  




	if ventana:Closed() then return false end 


	Time:Update()
	mundo:Update()
	mundo:Render()
	lienzo:Sync()
	
	if  mundo:Pick(0, 10, 5,0, -10, 5, pis,1.0, true )  then  


		ventana:Closed()

	end 

        
     

end

Any suggestions?

 

 

Link to comment
Share on other sites

  • Solution

The pick is working - you just are not confirming if the pick is occurring correctly.

if  mundo:Pick(0, 10, 5,0, -10, 5, pis,1.0, true )  then  
		ventana:Closed()
end 

ventana:Closed() does not close the window, it only checks if the window has been closed. Refer to the documentation: Window:Closed()

I would suggest doing a 'System:Print()' as a way to confirm if the pick was successful. But if you really want to exit the program after the first loop when the pick is successful then change the code to this:

if  mundo:Pick(0, 10, 5,0, -10, 5, pis,1.0, true )  then  
		System:Print("Pick Successful")
		return false
end 

Edit -- also, unless the user knows exactly what they are doing and what to expect, I would advise you to stay away from giving your pick a radius as its slower and may give unwanted results. I'd advise you to use the precise raycast by using a radius of '0'.

  • Thanks 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites


Okay, this is working, the learning process is very cruel when you use the translator and start testing and making mistakes to come to some conclusion. So I'm getting the hang of this little by little. Is there a way to see the beam? 


Another question, do I just put numbers here?
suelo:SetPickMode
( 0)
suelo:SetPickMode
( 1)

 

 

Link to comment
Share on other sites

Have I mentioned how much I dislike the tech *** forum? Fixed the OP's issue, but who knows because if the OP likes the answer, it removes the post from the order of the discussion. ****ing Garbage.

 

Anyways. your choices for SetPickMode() as found in the documentation:

  • 0: pick tests will skip this entity.
  • Entity::SpherePick: a sphere test with the entity pick radius will be used.
  • Entity::PolygonPick: if the entity is a model or a brush, a precise polygonal pick test will be performed.
  • Entity::BoxPick: a box test with the entity pick radius will be used

I'd advise you to RTM. <<-- polite version.

And no, you can't see the "beam". You can draw the "beam" if you wish using DrawLine or creating/scaling a polygon model from the start and end pick points. There are examples of this if you search the forum for "beam"

  • Thanks 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Ok, 
suelo:SetPickMode( suelo.PolygonPick, false ) 

 

ventana = Window:Create()
lienzo  = Context:Create( ventana )
mundo   = World:Create()

local sol = DirectionalLight:Create()
sol:SetRotation(90, 0, 0 )

local camara = Camera:Create()




local suelo = Model:Box()

suelo:SetScale(5, 0.2, 5 ) 
suelo:SetPosition( 0, -1, 5 ) 
suelo:SetPickMode( suelo.PolygonPick, false ) 



local punto = Model:Cone()
punto:SetPosition ( 0, 0, 5 ) 
punto:SetColor (1, 0, 0 ) 


local pis = PickInfo()

while true do  




	if ventana:Closed() then return false end 


	Time:Update()
	mundo:Update()
	mundo:Render()
	lienzo:Sync()
	
	if  mundo:Pick(0, 10, 5,0, -10, 5, pis,0, true )  then  

System:Print("Pick Successful")
		return false

	end 


        
     

Okay, this is working, now it's my turn to think about how to implement this so that a camera collides. 

 

 

Link to comment
Share on other sites

1 hour ago, AggrorJorn said:
ventana = Window:Create()
lienzo  = Context:Create( ventana )
mundo   = World:Create()

local sol = DirectionalLight:Create()
sol:SetRotation(90, 0, 0 )

local camara = Camera:Create()




local suelo = Model:Box()

suelo:SetScale(5, 0.2, 5 ) 
suelo:SetPosition( 0, -1, 5 ) 
suelo:SetPickMode( 0, true ) 



local punto = Model:Cone()
punto:SetPosition ( 0, 0, 5 ) 
punto:SetColor (1, 0, 0 ) 


local pis = PickInfo()

while true do  




	if ventana:Closed() then return false end 


	Time:Update()
	mundo:Update()
	mundo:Render()
	lienzo:Sync()
	
	if  mundo:Pick(0, 10, 5,0, -10, 5, pis,0, true )  then  

System:Print("Pick Successful")
		return false

	end 


        
     

end

Well, I'm telling you that even though it's at zero, the lightning still detects the ground from the cone. I'm confused. I'm confused. 

 

 

Link to comment
Share on other sites

8 minutes ago, Yue said:

Well, I'm telling you that even though it's at zero, the lightning still detects the ground from the cone. I'm confused. I'm confused. 

You are doing a World Pick on the global Y-axis from +10 to -10. The pick is returning that it successfully picked something between these two points. The raycast is not from the cone. The raycast starts at the (0,10.5) point in space. The raycast ends at (0,-10,5), If it hits anything, it will return true. You have the cone sitting right where this raycast is occurring. It is hitting the cone. Try reading the documentation and try out the examples. World:Pick()

  • Thanks 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

4 minutes ago, macklebee said:

You are doing a World Pick on the global Y-axis from +10 to -10. The pick is returning that it successfully picked something between these two points. The raycast is not from the cone. The raycast starts at the (0,10.5) point in space. The raycast ends at (0,-10,5), If it hits anything, it will return true. You have the cone sitting right where this raycast is occurring. It is hitting the cone. Try reading the documentation and try out the examples. World:Pick()

Ok, so as not to waste time, with this method I can set the collision for a third person camera, or do I have to think about something else?

 

 

Link to comment
Share on other sites

ventana = Window:Create()
lienzo  = Context:Create( ventana )
mundo   = World:Create()

local sol = DirectionalLight:Create()
sol:SetRotation(90, 0, 0 )

local camara = Camera:Create()




local suelo = Model:Box()

suelo:SetScale(5, 0.2, 5 ) 
suelo:SetPosition( 0, -1, 5 ) 
--suelo:SetPickMode( 0, true ) 



local cono = Model:Cone()
cono:SetPosition ( 0, 0, 5 ) 
cono:SetColor (1, 0, 0 ) 
cono:SetPickMode( 0, true ) 



local pis = PickInfo()

while true do  




	if ventana:Closed() then return false end 


	Time:Update()
	mundo:Update()
	mundo:Render()
	lienzo:Sync()
	
	if  mundo:Pick(cono:GetPosition(true).x, cono:GetPosition(true).y, cono:GetPosition(true).z ,   0, -10, 5, pis,0, true )  then  

System:Print("Pick Successful")
		suelo:SetColor( 1, 1, 0 ) 

	end 


        
     

end

Okay, I'm getting this, the plan is that the beam will turn with the cone to another entity, that's what I think is a possible way to detect a camera collision.  

 

 

Link to comment
Share on other sites

ventana = Window:Create()
lienzo  = Context:Create( ventana )
mundo   = World:Create()

local sol = DirectionalLight:Create()
sol:SetRotation(90, 0, 0 )

local camara = Camera:Create()


local suelo = Model:Box()

suelo:SetScale(5, 0.2, 5 ) 
suelo:SetPosition( 0, -1, 5 ) 
--suelo:SetPickMode( 0, true ) 

local cono = Model:Cone()
cono:SetPosition ( 0, 0, 5 ) 
cono:SetColor (1, 0, 0 ) 
cono:SetPickMode( 0, true ) 

camara:SetParent(cono,true)

local pis = PickInfo()

while true do  


cono:Turn(1, 0, 0 ) 

    if ventana:Closed() then return false end 


    Time:Update()
    mundo:Update()
    mundo:Render()
    lienzo:Sync()
    
    if  mundo:Pick(cono:GetPosition(true).x, cono:GetPosition(true).y, cono:GetPosition(true).z ,   camara:GetPosition(true).x, camara:GetPosition(true).y, camara:GetPosition(true).z, pis,0, true )  then  

System:Print("Pick Successful")
        suelo:SetColor( 1, 1, 0 ) 

    else 
    

    suelo:SetColor( 1, 0, 0 )

    end 


        
     

end


:)

 

 

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