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:OnEventBegin(value)
- if not StereoRendererRequestBus.Broadcast.IsRenderingToHMD() then
- --Set up raycast
- local rayCastConfig = RayCastConfiguration()
- 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)
- --Send notification when a hit occurs
- if hit1 then
- GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(hit1.entityId, "objectInFocus"), hit1.entityId)
- end
- --[[ Debug raycast
- Debug.Log("camera transform = "..tostring(cameraTransform))
- Debug.Log("rayCastConfig.origin = "..tostring(rayCastConfig.origin))
- Debug.Log("rayCastConfig.direction = "..tostring(rayCastConfig.direction))
- Debug.Log("************************")
- Debug.Log("hitCount = "..tostring(hitCount))
- Debug.Log("hit.entityId = "..tostring(hit1.entityId))
- ]]--
- end
- end
- function CameraRaycast:OnDeactivate()
- self.mouseXConnection:Disconnect()
- end
- return CameraRaycast
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement