Steve Scott Posted July 29, 2018 Share Posted July 29, 2018 Hello, I want to create a fishing system but I have to know, how can I calculate the position of the cursor when the player clicks on the water and how can I get if he clicks on the water or just on the ground, because at this point I want to create an object at the top of the water. Thanks in advance! ? Link to comment
SycroX Posted July 29, 2018 Share Posted July 29, 2018 getCursorPosition idk if there's a way to check if the player click on a water or on a ground but you can use this function to bring the cursor's position Link to comment
Addlibs Posted July 29, 2018 Share Posted July 29, 2018 You can getWorldFromScreenPosition with getCursorPosition to get the ground that's been clicked on, and then testLineAgainstWater from camera position to the ground you clicked to determine whether there was water in the way and the precise x, y and z position where water was found Link to comment
Discord Moderators Pirulax Posted July 29, 2018 Discord Moderators Share Posted July 29, 2018 (edited) Actually: function getCursorPosAtHeight(h) --// Calculate the cursorposition at the v3StartAz.z height. local v3CamPos = getCamera():getPosition() local v3Unit = v3CamPos-Vector3(getWorldFromScreenPosition(v2CursorPos.x, v2CursorPos.y, 1))--// Calculate how much going down 1 depth effects our z local zDistance = (v3CamPos.z-h)/v3Unit.z --// Get the height between the wanted height and the cam and devide it by the v3Unit.z, so we get how much units we need return Vector3(v3CamPos.x-v3Unit.x*zDistance, v3CamPos.y-v3Unit.y*zDistance, h)--// Calculate the cursor position at the given height. end Water is always at height 0. Now, to test that the user really clicked on water just use the mentioned function. testLineAgainstWater(getCamera():getPosition(), getWorldFromScreenPosition(v2CursorPos, 300)) If this returns true then he clicked at water. To get the water height juse use getCursorPosAtHeight(0) Edited July 29, 2018 by Pirulax Link to comment
Steve Scott Posted July 30, 2018 Author Share Posted July 30, 2018 (edited) On 2018. 07. 29. at 14:55, Pirulax said: Actually: function getCursorPosAtHeight(h) --// Calculate the cursorposition at the v3StartAz.z height. local v3CamPos = getCamera():getPosition() local v3Unit = v3CamPos-Vector3(getWorldFromScreenPosition(v2CursorPos.x, v2CursorPos.y, 1))--// Calculate how much going down 1 depth effects our z local zDistance = (v3CamPos.z-h)/v3Unit.z --// Get the height between the wanted height and the cam and devide it by the v3Unit.z, so we get how much units we need return Vector3(v3CamPos.x-v3Unit.x*zDistance, v3CamPos.y-v3Unit.y*zDistance, h)--// Calculate the cursor position at the given height. end Water is always at height 0. Now, to test that the user really clicked on water just use the mentioned function. testLineAgainstWater(getCamera():getPosition(), getWorldFromScreenPosition(v2CursorPos, 300)) If this returns true then he clicked at water. To get the water height juse use getCursorPosAtHeight(0) This getCursorPosAtHeight function only works if I create the object at client side but I want to bring it to server side Edited July 30, 2018 by tacsa Link to comment
SycroX Posted July 30, 2018 Share Posted July 30, 2018 3 minutes ago, tacsa said: This getCursorPosAtHeight function only works if I create the object at client side but I want to bring it to server side trigger Client/Server Event Link to comment
Steve Scott Posted July 30, 2018 Author Share Posted July 30, 2018 11 minutes ago, #َxLysandeR said: trigger Client/Server Event Yes, I know ? but for some reason it doesn’t work Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now