Jump to content

raycasting - need help


swipis
 Share

Recommended Posts

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. smile.png

 

Thanks

post-16770-0-92274000-1453559858_thumb.png

Link to comment
Share on other sites

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.

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

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?

Link to comment
Share on other sites

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.

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

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.

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...