Jump to content

Determine Map Floors and Walls When User Clicks


Xmlspy
 Share

Recommended Posts

Does anyone know a way to determine whether a user has clicked on the NavMesh? I'm trying to only allow clicks on the floors, which also means to exclude walls and other steep angled scenery, and I think that the good looking NavMesh of the map editor seems like the perfect thing to use for this task.

Link to comment
Share on other sites

Or set a custom collision response for the floors and the raycast. Then the raycast will only interact with the floor.

example-code:

Collision.MyFloors = 24
Collision:SetResponse(Collision.Character,Collision.MyFloors,1)
floor:SetCollisionType(Collision.MyFloors)
Collision.MyPick = 25
Collision:SetResponse(Collision.MyFloors, Collision.MyPick, 1)

 

or just set the walls to Collision.Prop, and give the pick a custom collisiontype that only interacts with the floors having a collisiontype of scene

 

or set the walls to have a pickmode of 0 ---

 

it really depends on what you want to have interaction with and what kind of interaction you want objects in your scene to have with each other

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

One more method--assign scripts with identifiable function.

 

How to:

  • Create a script that holds a "Script:IsWall()" function, and assign the script accordingly to each wall.
  • On the mouse click event one can use Josh's FindScriptedParent function, in FPSWeapon.lua, to identify whether an entity has the IsWall() function.
  • If the function is present and returns nill then that PickInfo entity is allowed to be clicked (and thus a floor). Otherwise it's a wall.

This same procedure can be used to instead give a script to each floor model, as hopefully there are less floors than walls created--thus requiring less time when designing a map. I'm not sure about the efficiency versus the other methods, but so far this works well for when the user clicks.

 

Some code:

-- Setup camera
Script.cam = Camera:Create()
-- position, rotation, etc

function Script:UpdateWorld()
  local win = Window:GetCurrent()
  local pickRadius = 0.01

  if win:MouseHit(2) then
     local pi = PickInfo()
     local mp = win:GetMousePosition()
     if (self.cam:Pick(mp.x, mp.y, pi, pickRadius, true)) then
        local inspect = self:FindScriptedParent(pi.entity, "IsWall")
        if inspect == nil then
           -- If it reaches this spot then the picked entity
           -- is not a wall, so it could be the floor.
           -- You could have a secondary inspection to determine if the
           -- user is clicking on a character or other type of model
           -- by using a similar procedure.
           -- Now you can use pi.position (or pi.position.x, pi.position.y, pi.position.z)
           -- to guide your characters to the clicked location.
        end
     end
  end
end

  • Upvote 2
Link to comment
Share on other sites

picking only works on entities with physics shapes. I am not sure if the navmesh has that.. You can also set a key value for your floors and for every pick check if the key is set.

That's actually not correct. Picking works on the visible geometry. (And in the case of CSG brushes, physics and visible geometry are the same.)

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...