Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. local CameraRaycast = {
  2. Properties = {
  3. }
  4. }
  5.  
  6. function CameraRaycast:OnActivate()
  7. self.mouse_xEventId = GameplayNotificationId(self.entityId, "mouse_x")
  8. self.mouseXConnection = GameplayNotificationBus.Connect(self, self.mouse_xEventId)
  9. end
  10.  
  11. function CameraRaycast:OnEventBegin(value)
  12. if not StereoRendererRequestBus.Broadcast.IsRenderingToHMD() then
  13.  
  14. --Set up raycast
  15. local rayCastConfig = RayCastConfiguration()
  16. local cameraTransform = TransformBus.Event.GetWorldTM(self.entityId)
  17. rayCastConfig.origin = cameraTransform:GetTranslation()
  18. rayCastConfig.maxDistance = 20
  19. rayCastConfig.physicalEntityTypes = 15
  20. rayCastConfig.maxHits = 10
  21. rayCastConfig.direction = cameraTransform:GetColumn(1)
  22.  
  23. --Execute raycast
  24. local rayCastResult = PhysicsSystemRequestBus.Broadcast.RayCast(rayCastConfig)
  25. local hitCount = rayCastResult:GetHitCount()
  26. local hasBlockingHit = rayCastResult:HasBlockingHit()
  27. local hit1 = rayCastResult:GetHit(1)
  28.  
  29. --Send notification when a hit occurs
  30. if hit1 then
  31. GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(hit1.entityId, "objectInFocus"), hit1.entityId)
  32. end
  33.  
  34. --[[ Debug raycast
  35. Debug.Log("camera transform = "..tostring(cameraTransform))
  36. Debug.Log("rayCastConfig.origin = "..tostring(rayCastConfig.origin))
  37. Debug.Log("rayCastConfig.direction = "..tostring(rayCastConfig.direction))
  38. Debug.Log("************************")
  39. Debug.Log("hitCount = "..tostring(hitCount))
  40. Debug.Log("hit.entityId = "..tostring(hit1.entityId))
  41. ]]--
  42. end
  43. end
  44.  
  45. function CameraRaycast:OnDeactivate()
  46. self.mouseXConnection:Disconnect()
  47. end
  48.  
  49. return CameraRaycast
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement