Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CameraRaycast = {
- Properties = {
- }
- }
- function CameraRaycast:OnActivate()
- self.mouse_xEventId = GameplayNotificationId(self.entityId, "mouse_x")
- self.mouseXConnection = GameplayNotificationBus.Connect(self, self.mouse_xEventId)
- end
- function CameraRaycast:Cast()
- --Set up raycast
- local rayCastConfig = RayCastConfiguration()
- -- ====================================
- -- THIS THINKS THAT self.entityId = nil
- -- ====================================
- Debug.Log("self.entityId = "..tostring(self.entityId))
- local cameraTransform = TransformBus.Event.GetWorldTM(self.entityId)
- rayCastConfig.origin = cameraTransform:GetTranslation()
- rayCastConfig.maxDistance = 20
- rayCastConfig.physicalEntityTypes = 15
- rayCastConfig.maxHits = 10
- rayCastConfig.direction = cameraTransform:GetColumn(1)
- --Execute raycast
- local rayCastResult = PhysicsSystemRequestBus.Broadcast.RayCast(rayCastConfig)
- local hitCount = rayCastResult:GetHitCount()
- local hasBlockingHit = rayCastResult:HasBlockingHit()
- local hit1 = rayCastResult:GetHit(1)
- return hit1
- end
- function CameraRaycast:OnEventBegin(value)
- -- ========================================
- -- THIS THINKS THAT self.entityId is valid
- -- ========================================
- Debug.Log("onEventBegin self.entityid = "..tostring(self.entityId))
- if not StereoRendererRequestBus.Broadcast.IsRenderingToHMD() then
- local hit1 = CameraRaycast:Cast()
- --Send notification when a hit occurs
- if hit1 then
- if WindowsConsoleManagerRequestBus.Broadcast.IsActive(hit1.entityId) then
- GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(hit1.entityId, "objectInFocus"), hit1.entityId)
- end
- end
- end
- end
- function CameraRaycast:OnDeactivate()
- self.mouseXConnection:Disconnect()
- end
- return CameraRaycast
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement