Slastraf Posted November 8, 2015 Share Posted November 8, 2015 For my towerdefense game I want to allow the player to place a turret into the 3d world with the mouse. I dont understand how to send a raycast from the camera when you click somewhere in the 3d world. For example if i want to place a block on the terrain by left clicking inside the game. Also I dont know how raycasting in general works . a link for that should be enough. thanks Friedrich Quote Link to comment Share on other sites More sharing options...
macklebee Posted November 8, 2015 Share Posted November 8, 2015 Camera Pick: http://www.leadwerks.com/werkspace/page/api-reference/_/camera/camerapick-r199 simple example: window = Window:Create("example",0,0,800,600) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:SetPosition(0,6,0) light = DirectionalLight:Create() light:SetRotation(45,45,0) terrain = Terrain:Create(128,true) box = Model:Box() box:SetPickMode(0) box:SetColor(1,0.5,0,1) camrot = camera:GetRotation() gx=Math:Round(context:GetWidth()/2) gy=Math:Round(context:GetHeight()/2) move = 0 strafe = 0 while window:KeyDown(Key.Escape)==false do if window:Closed() then break end mpos = window:GetMousePosition() dx = mpos.x - gx dy = mpos.y - gy camrot.x = camrot.x + dy / 10.0 camrot.y = camrot.y + dx / 10.0 camera:SetRotation(camrot) window:SetMousePosition(gx,gy) move = Math:Curve(((window:KeyDown(Key.W)and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0)),move,10) strafe = Math:Curve(((window:KeyDown(Key.D)and 1 or 0) - (window:KeyDown(Key.A) and 1 or 0)),strafe,10) camera:Move(strafe,0,move) if window:MouseHit(1) then pickinfo = PickInfo() if (camera:Pick(mpos.x,mpos.y,pickinfo,0,true)) then box:SetPosition(pickinfo.position) end end Time:Update() world:Update() world:Render() context:Sync(true) end 1 Quote 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 More sharing options...
Thirsty Panther Posted November 8, 2015 Share Posted November 8, 2015 I discuss camera pick info here. http://www.leadwerks.com/werkspace/topic/13394-operation-wolf/ 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.