I am using the raycasting code to determine if an object already exists at the given location:
Function GetObjectIDAtLocation(x, y, z, distance)
ExitFunction ObjectRayCast(0, x, y-distance, z, x, y, z)
EndFunction 0
When the virtual button is pressed a check is made and if the player hasn't spawned a new defence it is created at that location:
function getJoystickButtons()
if GetVirtualButtonPressed(OBJECT_ID_JOYSTICK_BUTTON)
objectid as integer
objectid = GetObjectIDAtLocation(cursor.x, 0, cursor.z, 0.50)
consoleLog(2, "Object ID: " + str(objectid), 300, 170)
if objectid < 99999
createDefense(cursor.x, cursor.z)
endif
endif
endfunction
function createDefense(cellx, cellz)
playerdefense[playerdefensecounter].x = cellx * 1
playerdefense[playerdefensecounter].z = cellz * 1
playerdefense[playerdefensecounter].id = CreateObjectSphere(1, 10, 10)
SetObjectPosition(playerdefense[playerdefensecounter].id, playerdefense[playerdefensecounter].x, 2, playerdefense[playerdefensecounter].z)
SetObjectColor(playerdefense[playerdefensecounter].id, DEFENSE_COLOR_RED, DEFENSE_COLOR_GREEN, DEFENSE_COLOR_BLUE, 100)
consoleLog(3, "Object Created: " + str(playerdefense[playerdefensecounter].id), 300, 185)
consoleLog(4, "Object X: " + str(playerdefense[playerdefensecounter].x), 300, 200)
consoleLog(5, "Object Z: " + str(playerdefense[playerdefensecounter].z), 300, 215)
endfunction
The issue I am having is even when a new defense is spawned it still returns that no object is there. If I increase the distance to .6 then it detects the floor as an object and no defenses can be created. Any ideas, I am totally stumped on this one.