swipis Posted January 23, 2016 Share Posted January 23, 2016 Hello guys! I need some help with raycasting. scene is very simple have cube (player) and the wall (player is set to Character collision type and wall is set to debris). down bellow scene picture. Here is the code if window:MouseDown(Key.LButton) then local pickInfo = PickInfo() local point1 = self.entity:GetPosition() local point2 = self.rayWall:GetPosition()--Transform:Point(0,0,1000, self.rayWall,nil) if self.entity.world:Pick(point1, point2, pickInfo, 0, true, Collision.Prop) then System:Print("Picked!!!") end end so there are problem in output 'Picked!!!' should come up when ray hits the wall, but 'Picked!!' comes when I click anywhere. P.S.I'am new at this game engine and LUA scripting. And not sure how raycasting works. Thanks Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 23, 2016 Share Posted January 23, 2016 Assuming the raycast is not hitting the player, you are performing a World:Pick() which always does the raycast between two defined points in space. So you clicking anywhere with the mouse has no bearing on the points used in the your code (other than causing the pick to occur). A Camera:Pick() uses screen coordinates and you can use the mouse position to determine those but typically you are using a first/third person view with the player. You could just put a defined second position away from the player to see if the world pick intersects with anything, but it really depends on what your goal is with performing a raycast. 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...
swipis Posted January 23, 2016 Author Share Posted January 23, 2016 looks like this code should work if window:MouseDown(Key.LButton) then local pickinfo = PickInfo() local p = window:GetMousePosition() if (self.camera:Pick(p.x,p.y,pickinfo,pickradius,true)) then self.picksphere:Show() self.picksphere:SetPosition(pickinfo.position) end end but in this code (if I understand correctly) ray casting from camera to the 'wall', but I need cast from the player. any help? Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 23, 2016 Share Posted January 23, 2016 Is the view going to be from the player's perspective or will the camera be showing the scene like your picture above? If from the player's perspective, then your code that you just posted will work. If the camera is not looking from the player's perspective, then there a couple of ways to perform the pick... but you need to explain what is the raycast's purpose. Do you want the ray to only shoot out a certain distance from the player's +Z axis or do you want to always check to see if anything is blocking the ray between the player and the wall? If you are just performing a world pick from the player to the wall, I am not sure what exactly you are trying to accomplish as it will always return true. 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...
swipis Posted January 23, 2016 Author Share Posted January 23, 2016 ok, I will try to explain what I looking for . so what I trying to get - there are space and cube are in space so when I click left mouse button on empty space I need that cube start flying to that point where I clicked. so I think I need cast ray from the cube. this code will work (i think) just one problem cube blocking ray if I click on him. Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 23, 2016 Share Posted January 23, 2016 this code will work (i think) just one problem cube blocking ray if I click on him. Set the player's PickMode to 0 to disable picking it. See Entity:SetPickMode() for more details. 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...
swipis Posted January 23, 2016 Author Share Posted January 23, 2016 ok, I will look at this solution tomorrow. thank you Quote Link to comment Share on other sites More sharing options...
swipis Posted January 24, 2016 Author Share Posted January 24, 2016 Looks like Entity:SetPickMode() not working for me 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.