CangoJoe Posted October 4, 2017 Share Posted October 4, 2017 Hey all, I thought I'd try my hand out at another Leadwerks Tournament game. I wanted to make a Concentration type game where you select 2 crates and compare them. I used a modified version of the Spectator.lua script where I locked the camera in place, disabled movement and enabled the onscreen mouse. The player will click Mouse Button 1 to select 2 crates and then the crates are compared. The problem I'm having is detecting where the cursor (MousePosition) is in relation to the world (what its hovering over) in order to determine which crate was clicked. Is there a way to convert mouse position to a world position? I was thinking I could do something as seen below in order to Pick() objects below the cursor/MousePosition (pseudo code): If MouseDown(1) If world:Pick(MousePositionVector, WorldPositionVector, pickinfo, 0, true, 1) then IsValidCrate() --Determine if a crate was clicked CompareCrate() --Compare crate DoStuff() --Despawn crates, tally score, fanfare, etc.. End End Perhaps there's a better way? Thanks in advance for any input! -can Quote Link to comment Share on other sites More sharing options...
Solution AggrorJorn Posted October 4, 2017 Solution Share Posted October 4, 2017 Pseudo approach Create a vector3 that represents your mouse in 3d. Use this https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_Camera_UnProject By changing the Z value of the above vector you determine how far the pick goes. Your raycast now 'shoots' from the mouseposition to the direction the camera is looking at with a given (z axis) length. Quote Link to comment Share on other sites More sharing options...
CangoJoe Posted October 4, 2017 Author Share Posted October 4, 2017 Thanks AggrorJorn That's exactly what I was looking for! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.