protected virtual void CreateBullet(Mode mode) { Bullet obj = (Bullet)Entities.Instance.Create(mode.typeMode.BulletType, Parent); obj.SourceUnit = GetParentUnitHavingIntellect(); obj.Position = GetFirePosition(mode.typeMode); //Correcting position at a shot in very near object (when the point of a shot inside object). { Vec3 startPos = Position; if (AttachedMapObjectParent != null) { startPos = AttachedMapObjectParent.Position; } Ray ray = new Ray(startPos, obj.Position - startPos); if (ray.Direction != Vec3.Zero) { RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (mapObject != null) { if (mapObject == this) { continue; } if (mapObject == this.AttachedMapObjectParent) { continue; } } obj.Position = result.Position - ray.Direction * .01f; break; } } } Quat rot = GetFireRotation(mode.typeMode); Radian dispersionAngle = mode.typeMode.DispersionAngle; if (dispersionAngle != 0) { EngineRandom random = World.Instance.Random; Mat3 matrix; matrix = Mat3.FromRotateByX(random.NextFloat() * MathFunctions.PI * 2); matrix *= Mat3.FromRotateByZ(random.NextFloat() * dispersionAngle); rot *= matrix.ToQuat(); } obj.Rotation = rot; obj.PostCreate(); //set damage coefficient float coef = obj.DamageCoefficient; Unit unit = GetParentUnitHavingIntellect(); if (unit != null && unit.BigDamageInfluence != null) { coef *= unit.BigDamageInfluence.Type.Coefficient; } obj.DamageCoefficient = coef; }