private void OldBulletHit(int cmdSeq, DefaultBulletSegment segment, ICompensationWorld world) { RaycastHit camDirHit; if (world.Raycast(segment.RaySegment, out camDirHit, _hitboxLayerMask)) { _bulletHitHandler.OnHit(cmdSeq, segment.BulletEntity, camDirHit, world); } }
private void OldRaycast() { ICompensationWorld lastCompensationWorld = null; foreach (var segment in _allThrowingSegments) { if (!segment.IsValid) { continue; } if (lastCompensationWorld != null) { if (lastCompensationWorld.ServerTime != segment.ServerTime) { lastCompensationWorld.Release(); lastCompensationWorld = _compensationWorldFactory.CreateCompensationWorld(segment.ServerTime); } } else { lastCompensationWorld = _compensationWorldFactory.CreateCompensationWorld(segment.ServerTime); if (lastCompensationWorld == null) { _logger.ErrorFormat("create compensation world at time {0}, FAILED", segment.ServerTime); } else { if (_logger.IsDebugEnabled) { _logger.DebugFormat("create compensation world at time {0}, SUCC", segment.ServerTime); } } } if (lastCompensationWorld != null) { RaycastHit hit; lastCompensationWorld.Self = segment.ThrowingEntity.ownerId.Value; lastCompensationWorld.ExcludePlayerList = segment.ExcludePlayerList; if (lastCompensationWorld.Raycast(segment.RaySegment, out hit, _layerMask)) { CollisionHandler(segment, hit); } } } if (lastCompensationWorld != null) { lastCompensationWorld.Release(); } }
private void NewBulletHit(int cmdSeq, DefaultBulletSegment segment, ICompensationWorld world) { RaycastHit camDirHit; segment.BulletEntity.IsNew = false; RaycastHit gunDirHit; var camRaySegment = segment.RaySegment; bool checkGunDirObstacle = false; while (segment.BulletEntity.IsValid && world.Raycast(camRaySegment, out camDirHit, _hitboxLayerMask)) { if (!checkGunDirObstacle) { checkGunDirObstacle = true; //如果击中物体,从枪口向击中位置做检测,如果有物体,则使用枪口方向的结果 var startPosition = segment.BulletEntity.GunEmitPosition; var target = camDirHit.point; var dir = target - startPosition; var blockCheckSegment = new RaySegment() { Length = Vector3.Distance(target, startPosition) - RaycastStepOffset, Ray = new Ray(startPosition, dir.normalized), }; while (segment.BulletEntity.IsValid && world.Raycast(blockCheckSegment, out gunDirHit, _hitboxLayerMask)) { _bulletHitHandler.OnHit(cmdSeq, segment.BulletEntity, gunDirHit, world); blockCheckSegment.Ray.origin = gunDirHit.point + blockCheckSegment.Ray.direction * RaycastStepOffset; } } if (segment.BulletEntity.IsValid) { _bulletHitHandler.OnHit(cmdSeq, segment.BulletEntity, camDirHit, world); camRaySegment.Ray.origin = camDirHit.point + camRaySegment.Ray.direction * RaycastStepOffset; } } if (segment.BulletEntity.IsValid) { if (!checkGunDirObstacle) { //如果没有击中物体,从枪口向第一帧末子弹到达的位置做检测,如果有物体,使用枪口方向的结果 var startPosition = segment.BulletEntity.GunEmitPosition; var target = segment.RaySegment.Ray.direction * segment.RaySegment.Length + segment.RaySegment.Ray.origin; var dir = target - startPosition; var blockCheckSegment = new RaySegment() { Length = Vector3.Distance(target, startPosition) - RaycastStepOffset, Ray = new Ray(startPosition, dir.normalized), }; while (segment.BulletEntity.IsValid && world.Raycast(blockCheckSegment, out gunDirHit, _hitboxLayerMask)) { checkGunDirObstacle = true; _bulletHitHandler.OnHit(cmdSeq, segment.BulletEntity, gunDirHit, world); blockCheckSegment.Ray.origin = gunDirHit.point + blockCheckSegment.Ray.direction * RaycastStepOffset; } } } }