Jump to content

Pick is working realy wired


Andy90
 Share

Go to solution Solved by Josh,

Recommended Posts

Hello :) the camera pick is working realy wired for me. You can see it within the video 2023-09-30 02-36-14 (streamable.com). This is my code

 

function Script:Shot()
	--Create a sphere to indicate where the pick hits
	local pickradius = 0.1;

	picksphere = Model:Sphere()
	picksphere:SetColor(1.0, 0.0, 0.0)
	picksphere:SetPickMode(0)
	picksphere:SetScale(pickradius * 2.0)
	picksphere:Hide()

	picksphere:Hide()
	local pickinfo = PickInfo()
	local p = window:GetMousePosition()
	if (self.cam:Pick(p.x, p.y, pickinfo, pickradius, true, Collision.Prop)) then
		picksphere:Show();
		picksphere:SetPosition(pickinfo.position);
		local name = pickinfo.entity:GetKeyValue("name");
		pickinfo.entity:Hide();
		System:Print(name);
	end
end

 

Link to comment
Share on other sites

  • Solution

Based on your video, I think the problem is that you are expecting it to pick the closest object. There is an optional value you should set to get this behavior. Otherwise, it just acts as a line-of-sight test and returns if any object is hit.

Picking does not work on animated models because the vertices only move around on the GPU. In my AI scripts I handled this by using the box pick mode on all children of the model, then disabling picking on the model itself:

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

This provides a close but efficient way to intersect an animated model with bullets and things.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

5 hours ago, Josh said:

Picking does not work on animated models because the vertices only move around on the GPU. In my AI scripts I handled this by using the box pick mode on all children of the model, then disabling picking on the model itself:

Thank you, this is very helpful. I believe I've properly configured the parameters in my pick function to acquire the closest target. However, there's a chance I may have misunderstood something.

self.cam:Pick(p.x, p.y, pickinfo, pickradius, true, Collision.Prop)

-----

I also edited the model a bit because at some parts of the body was no hit registration. So i added some spheres and asign them an invisible hitbox material. Works great so far 

image.thumb.png.adf9112f1061646fa13f08fff48ddcc9.png

Link to comment
Share on other sites

7 hours ago, Andy90 said:

Thank you, this is very helpful. I believe I've properly configured the parameters in my pick function to acquire the closest target. However, there's a chance I may have misunderstood something.

self.cam:Pick(p.x, p.y, pickinfo, pickradius, true, Collision.Prop)

This looks correct to me.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Did you self-scale the model ? or scale via the editor's 'Resize' feature, it actually makes a huge difference.   I found it way helpful to scale any animated mesh or boned objects outside of leadwerks and just bring it in at it's actual size, You cant resize then collapse a boned mesh in the editor without deleting it's hierarchy and that screws everything up..  Normal meshes you can resize in the editor then collapse when your done and it will retain a 1 to 1 scale which is what you want for picks and such.

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