I have made some progress with this, but just can't get the Entity to follow the Mouse with any reasonable precision
This is my current code:
- Code: Select all
local mY = screen.getMouseY ( )
local mX = screen.getMouseX ( )
local sH = screen.getHeight ( )
local sW = screen.getWidth ( )
local bUpdate = true
if ( mY < 1 or mY > sH or mX < 1 or mX > sW ) then
bUpdate = false
end
if ( bUpdate ) then
local xRay, yRay, zRay = sky.raycastToCursor ( )
local zOrig = zRay
local camX, camY, camZ = entity.getPosition ( entity.getIDFromTag ( "SCC_Cam" ) )
xRay = camX - xRay
yRay = camY - yRay
zRay = camZ - zRay
xRay, yRay, zRay = vector3.normalisedCopy ( xRay, yRay, zRay )
local fMultX = ( mX / sW ) * 75
local fMultZ = ( mY / sH ) * 75
xRay = xRay * -fMultX
zRay = zRay * fMultZ
if ( zOrig < -100 ) then
yRay = yRay + 10
else
yRay = yRay
end
entity.setPosition ( tempID, xRay, yRay, zRay )
end
which sort of works, but not very well.
The issues are many, such as:
- entity offset in X and a bit in Z
entity swaps to opposite side of mouse at certain points
entity only goes so far in Z (restricted by fMultX & fMultZ, but changing this bigger/smaller makes things worse)
So, unless anyone has any bright ideas, I might put this aside for later and just implement "click to place" instead.
Thanks for reading
Shando
[UPDATE]
Well blow me down with a feather, I've got it working
The problem was that I had set a query flag on the board models and this meant that the mouse ray wasn't detecting them at all!! Remove the query flag and voila! works perfectly
[UPDATE 2]
Looks like I spoke too soon removing the query flag now means I can't detect which model I'm hitting with the ray as isColliding will no longer work