Jump to content

raycast to show hidden objects


DooMAGE
 Share

Recommended Posts

Hello,

I'm trying to modify the FPSPlayer.lua to show hidden objects with the flashlight, but its not working.

What I am doing wrong? :P

function Script:UpdateWorld()
  local pickinfo=PickInfo()
	
  local p = self.flashlight:GetPosition() 
    if (self.camera:Pick(p.x,p.y,pickinfo,0.5,true)) then
      pickinfo.entity:Show()
    end
end

Edit - I guess I should use world:pick instead?

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

I think it works https://www.leadwerks.com/community/topic/2351-parented-hidden-objects-are-visible-for-raycasts/#comment-21510

Also I am trying to debug with:

System:Print(pickinfo.entity.position)

And it only shows "0.000000, 0.000000, 0.000000" no matter to where I look.
So I think I am using pick wrong :/

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

Update.

It's working now, I use world:pick to raycast and test if the pickinfo I got is the object I want to show.
Since the raycast wont work with hidden objects, I am changing its materials.

Now the catch is, How can I detect if my raycast is not hitting the object I got before, so I can put the original material back?

Tried this but my lastValidPickinfo thing is not working:

if self.entity.world:Pick(p0,p1, pickinfo, 0, true) then 
  if pickinfo ~= nil then
    if pickinfo.entity ~= nil and pickinfo.entity:GetKeyValue("name") ~= "" then
      self.lastValidPickinfo = pickinfo
      pickinfo.entity.script.showObject = true

      if self.lastValidPickinfo.entity:GetKeyValue("name") == "" then
        self.lastValidPickinfo.entity.script.showObject = false
      end
  end
end

 

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

Some pseudo code:

if pickinfo ~= nil then
	if pickinfo.entity ~= nil and pickinfo.entity:GetKeyValue("name") ~= "" then

		--If there is a lastPickInfo, compare it to the current pickinfo name
		if(self.lastValidPickinfo ~= nil then
			if self.lastValidPickinfo.entity:GetKeyValue("name") ~= pickinfo.entity:GetKeyValue("name")) then
				--Now the pick is different than previous picked obj
				 self.lastValidPickinfo.script.showObject = false
			end
		end
		
		self.lastValidPickinfo = pickinfo
		pickinfo.entity.script.showObject = true
	end
end

 

  • Upvote 1
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...