Jump to content

Making Camera Pick have a limited range?


Pastaspace
 Share

Recommended Posts

What I am trying to work is out code that allows the player to use objects, in this case by pressing the E key when their mouse is over a usable object.

Now this is done, the problem is the range. Using a pick, the camera will pick something regardless of its range to the player. So even if the button I use is fifteen miles away, it'll still activate it as long as the mouse is technically over it.

My question is, Leadwerks 2.5 allowed us to give the pick a distance (anything past that distance was ignored basically), how do I do this in 3.2?

tp_toPick.distance doesn't work. It always returns -1 regardless of distance.

Basic code is here, with the action code cut out.

 

if (window->KeyHit(Key::E))
{

if (camera->Pick(centerMouse.x, centerMouse.y, tp_toPick, 0, true) == 1)
{
//If things are a certain distance, perform the relevant action on the pick.
}
}

Link to comment
Share on other sites

Try to use a World Pick it gives you a starting Vec3 point and an ending Vec3 point for your pick.

 

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/world/worldpick-r502

 

If you need the camera pick for whatever reason I think you could also calculate the distance between your pick point and your pick start manually. Something like --

 

if pickstart:GetPosition():DistanceToPoint(pickend:GetPosition()) < maxdistance then etc.

 

pickstart, pickend and maxdistance are the changeable values.

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

Link to comment
Share on other sites

You may have tried this before but referring back to my example above what if you made pickend equal to the pickinfo.position? That should get rid of the distance between entities problem and should instead give you the distance between your entity and your pick position. Or tp_toPick.position in your case.

It would look like

if self.entity:GetPosition():DistanceToPoint(pickinfo.position) < maxdistance then etc.

Check out my game Rogue Snowboarding- 

https://haydenmango.itch.io/roguesnowboarding

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