Jump to content

[HELP] Click on water // fishing system


Recommended Posts

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
  • Discord Moderators

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 by Pirulax
Link to comment
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 by tacsa
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...