public override void FireBullet(Player player, Vector3 origin, Vector3 dir, Vector3 recoil, int blockDamage, float playerDamage, float maxDist = float.MaxValue) { Ray ray = new Ray(origin, dir + recoil); TerrainRaycastResult result = TerrainPhysics.Raycast(ray, true, maxDist); if (result.Intersects) { result.Chunk.DamageBlock(result.BlockIndex.Value, blockDamage); if (DashCMD.GetCVar <bool>("cl_impacts")) { debugRenderer.AddBulletImpact(ray.Origin + ray.Direction * result.IntersectionDistance.Value, Color.Red); } } }
public override void FireBullet(Player player, Vector3 origin, Vector3 dir, Vector3 recoil, int damage, float playerDamage, float maxDist = float.MaxValue) { // Signal server that we fired a bullet at this time OurPlayer.ClientSnapshot.BulletSnapshot.EnqueueBullet(new NetworkBullet(origin, Camera.Active.Yaw, Camera.Active.Pitch)); // Simulate bullet locally if enabled if (DashCMD.GetCVar <bool>("cl_impacts")) { Ray ray = new Ray(origin, dir + recoil); TerrainRaycastResult result = TerrainPhysics.Raycast(ray, true, maxDist); ClientPlayer hitPlayer = null; float? hitPlayerAt = null; foreach (ClientPlayer otherPlayer in players.Values) { if (otherPlayer != player) { if (DashCMD.GetCVar <bool>("cl_impacts")) { debugRenderer.AddPlayerRollback(otherPlayer.Transform.Position, Color.Green); } Ray newRay = new Ray(origin - otherPlayer.Transform.Position, dir); float?dist; if (newRay.Intersects(otherPlayer.GetOrientatedBoundingBox(), out dist)) { if (!hitPlayerAt.HasValue || dist.Value < hitPlayerAt.Value) { hitPlayer = otherPlayer; hitPlayerAt = dist.Value; } } } } if (result.Intersects && (!hitPlayerAt.HasValue || (hitPlayerAt.Value > result.IntersectionDistance.Value))) { debugRenderer.AddBulletImpact(ray.Origin + ray.Direction * result.IntersectionDistance.Value, Color.Red); } else if (hitPlayerAt.HasValue) { debugRenderer.AddBulletImpact(ray.Origin + ray.Direction * hitPlayerAt.Value, Color.Red); } } }
public PlayerRaycastResult RaycastPlayer(Vector3 origin, Player player, float maxDist = 2000f) { Vector3 dir = (player.Transform.Position - origin).Normalize(); Ray ray = new Ray(origin, dir); TerrainRaycastResult tResult = TerrainPhysics.Raycast(ray, true, maxDist); float?dist; PhysicsBodyComponent playerPhysics = player.GetComponent <PhysicsBodyComponent>(); bool hitPlayer = ray.Intersects(playerPhysics.GetCollider(), out dist); if (hitPlayer && dist.Value <= maxDist && (!tResult.Intersects || dist.Value < tResult.IntersectionDistance.Value)) { return(new PlayerRaycastResult(ray, true, ray.Origin + ray.Direction * dist.Value, dist, player)); } else { return(new PlayerRaycastResult(ray)); } }