|
|
@@ -210,9 +210,9 @@ function MoveCamera(timeStep)
|
|
|
end
|
|
|
|
|
|
function SetPathPoint()
|
|
|
- local result, hitPos, hitDrawable = Raycast(250.0)
|
|
|
+ local hitPos, hitDrawable = Raycast(250.0)
|
|
|
local navMesh = scene_:GetComponent("NavigationMesh")
|
|
|
- if result then
|
|
|
+ if hitPos then
|
|
|
local pathPos = navMesh:FindNearestPoint(hitPos, Vector3.ONE)
|
|
|
|
|
|
if input:GetQualifierDown(QUAL_SHIFT) then
|
|
|
@@ -230,13 +230,13 @@ end
|
|
|
|
|
|
function AddOrRemoveObject()
|
|
|
-- Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
|
|
|
- local result, hitPos, hitDrawable = Raycast(250.0)
|
|
|
- if result then
|
|
|
+ local hitPos, hitDrawable = Raycast(250.0)
|
|
|
+ if hitDrawable then
|
|
|
-- The part of the navigation mesh we must update, which is the world bounding box of the associated
|
|
|
-- drawable component
|
|
|
local updateBox = nil
|
|
|
|
|
|
- local hitNode = hitDrawable:GetNode()
|
|
|
+ local hitNode = hitDrawable.node
|
|
|
if hitNode.name == "Mushroom" then
|
|
|
updateBox = hitDrawable.worldBoundingBox
|
|
|
hitNode:Remove()
|
|
|
@@ -268,13 +268,11 @@ function CreateMushroom(pos)
|
|
|
end
|
|
|
|
|
|
function Raycast(maxDistance)
|
|
|
- local hitPos = nil
|
|
|
- local hitDrawable = nil
|
|
|
|
|
|
local pos = ui.cursorPosition
|
|
|
-- Check the cursor is visible and there is no UI element in front of the cursor
|
|
|
if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
|
|
|
- return false, nil, nil
|
|
|
+ return nil, nil
|
|
|
end
|
|
|
|
|
|
local camera = cameraNode:GetComponent("Camera")
|
|
|
@@ -283,13 +281,10 @@ function Raycast(maxDistance)
|
|
|
local octree = scene_:GetComponent("Octree")
|
|
|
local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
|
|
|
if result.drawable ~= nil then
|
|
|
- -- Calculate hit position in world space
|
|
|
- hitPos = cameraRay.origin + cameraRay.direction * result.distance
|
|
|
- hitDrawable = result.drawable
|
|
|
- return true, hitPos, hitDrawable
|
|
|
+ return result.position, result.drawable
|
|
|
end
|
|
|
|
|
|
- return false, nil, nil
|
|
|
+ return nil, nil
|
|
|
end
|
|
|
|
|
|
function HandleUpdate(eventType, eventData)
|