Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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:Cast()
  12. --Set up raycast
  13. local rayCastConfig = RayCastConfiguration()
  14. -- ====================================
  15. -- THIS THINKS THAT self.entityId = nil
  16. -- ====================================
  17. Debug.Log("self.entityId = "..tostring(self.entityId))
  18. local cameraTransform = TransformBus.Event.GetWorldTM(self.entityId)
  19. rayCastConfig.origin = cameraTransform:GetTranslation()
  20. rayCastConfig.maxDistance = 20
  21. rayCastConfig.physicalEntityTypes = 15
  22. rayCastConfig.maxHits = 10
  23. rayCastConfig.direction = cameraTransform:GetColumn(1)
  24.  
  25. --Execute raycast
  26. local rayCastResult = PhysicsSystemRequestBus.Broadcast.RayCast(rayCastConfig)
  27. local hitCount = rayCastResult:GetHitCount()
  28. local hasBlockingHit = rayCastResult:HasBlockingHit()
  29. local hit1 = rayCastResult:GetHit(1)
  30.  
  31. return hit1
  32. end
  33.  
  34. function CameraRaycast:OnEventBegin(value)
  35. -- ========================================
  36. -- THIS THINKS THAT self.entityId is valid
  37. -- ========================================
  38. Debug.Log("onEventBegin self.entityid = "..tostring(self.entityId))
  39. if not StereoRendererRequestBus.Broadcast.IsRenderingToHMD() then
  40. local hit1 = CameraRaycast:Cast()
  41. --Send notification when a hit occurs
  42. if hit1 then
  43. if WindowsConsoleManagerRequestBus.Broadcast.IsActive(hit1.entityId) then
  44. GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(hit1.entityId, "objectInFocus"), hit1.entityId)
  45. end
  46. end
  47. end
  48. end
  49.  
  50. function CameraRaycast:OnDeactivate()
  51. self.mouseXConnection:Disconnect()
  52. end
  53.  
  54. return CameraRaycast
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement