public override void OnOwner(PlayerCommand cmd, BoltEntity entity) { if (entity.isOwner) { IPlayerState state = entity.GetState <IPlayerState>(); PlayerController controller = entity.GetComponent <PlayerController>(); Vector3 pos; Quaternion look; // this calculate the looking angle for this specific entity PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, state.pitch, out pos, out look); // display debug Debug.DrawRay(pos, look * Vector3.forward); using (var hits = BoltNetwork.RaycastAll(new Ray(pos, look * Vector3.forward), cmd.ServerFrame)) { for (int i = 0; i < hits.count; ++i) { var hit = hits.GetHit(i); var serializer = hit.body.GetComponent <PlayerController>(); if ((serializer != null) && (serializer.state.team != state.team)) { serializer.ApplyDamage(controller.activeWeapon.damagePerBullet); } } } } }
private void HandleFireCommand(MoveAndShootFireCommand fireCommand, bool reset) { if (reset) { SetState(fireCommand.Result.Position, fireCommand.Result.Velocity, fireCommand.Result.Yaw); } else if (fireCommand.IsFirstExecution) { var inputType = fireCommand.Input.Type; var weapon = inputType ? weaponDamage : weaponHeal; if (weapon.NextFireFrame <= BoltNetwork.ServerFrame) { weapon.NextFireFrame = BoltNetwork.ServerFrame + weapon.fireRate; if (weapon.TriggerState != null) { weapon.TriggerState.Invoke(); } if (entity.IsOwner) { var fireOrigin = weapon.fx.transform; var fireOriginForward = fireOrigin.forward; Vector3 pos = fireOrigin.position + (fireOriginForward * 0.5f); Ray ray = new Ray(pos, fireOriginForward); using (var hits = BoltNetwork.RaycastAll(ray, fireCommand.ServerFrame)) { for (int i = 0; i < hits.count; ++i) { var hit = hits.GetHit(i); // Check if weapon can effect at that distance based on the weapon range if (hit.distance <= weapon.maxEffectRange) { var serializer = hit.body.GetComponent <MoveAndShoot_PlayerController>(); if (serializer != null) { // Hit Point HitHandler(serializer.entity, weapon.amount, weapon.type, ray.GetPoint(hit.distance)); } } } } } } fireCommand.Result.Velocity = _cc.velocity; fireCommand.Result.Position = transform.localPosition; fireCommand.Result.Yaw = transform.localRotation.eulerAngles.y; } }