protected override MatrixD GetEffectMatrix(float muzzleOffset) { if (m_raycastComponent.HitCubeGrid == null || m_raycastComponent.HitBlock == null || !(Owner is MyCharacter)) { return(MatrixD.CreateWorld(m_gunBase.GetMuzzleWorldPosition(), WorldMatrix.Forward, WorldMatrix.Up)); } var headMatrix = Owner.GetHeadMatrix(true); var aimPoint = m_raycastComponent.HitPosition; var dist = Vector3.Dot(aimPoint - m_gunBase.GetMuzzleWorldPosition(), headMatrix.Forward); dist -= 0.1f; var target = m_gunBase.GetMuzzleWorldPosition() + headMatrix.Forward * (dist * muzzleOffset) + headMatrix.Up * 0.04f; MatrixD matrix = MatrixD.CreateWorld(dist > 0 && muzzleOffset == 0 ? m_gunBase.GetMuzzleWorldPosition() : target, WorldMatrix.Forward, WorldMatrix.Up); //var normal = ((MyCharacter) CharacterInventory.Owner).AimedPointNormal; Vector3D right = Vector3D.TransformNormal(matrix.Right, MatrixD.CreateFromAxisAngle(matrix.Up, -MathHelper.ToRadians(45))); right = MyUtilRandomVector3ByDeviatingVector.GetRandom(right, MyUtils.GetRandomFloat(0, 0.35f)); Vector3D up = Vector3D.Cross(right, matrix.Forward); Vector3D forward = Vector3D.Cross(up, right); return(MatrixD.CreateWorld(matrix.Translation, forward, up)); //matrix = Matrix.CreateFromAxisAngle(matrix.Up, -MathHelper.ToRadians(75)) * matrix; //return Matrix.CreateWorld(matrix.Translation, matrix.Forward, Vector3.Reflect(matrix.Forward, normal)); }
// Every child of this base class must implement Shot() method, which shots projectile or missile. // Method returns true if something was shot. False if not (because interval between two shots didn't pass) public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo) { if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < MyCannonConstants.SHOT_INTERVAL_IN_MILISECONDS && !IsDummy) { return(false); } // Throw ship backward (by deviated vector) this.Parent.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, MyUtilRandomVector3ByDeviatingVector.GetRandom(Vector3.Backward, MathHelper.ToRadians(5)) * MyMwcUtils.GetRandomFloat(40000, 50000), null, null); // Play missile launch cue (one-time) //AddWeaponCue(MySoundCuesEnum.WepMissileLaunch3d); AddWeaponCue(MySoundCuesEnum.WepCannon3d); Vector3 forwardVelocity = MyMath.ForwardVectorProjection(this.WorldMatrix.Forward, GetParentMinerShip().Physics.LinearVelocity); //Vector3 forwardVelocity = this.WorldMatrix.Forward; Vector3 deviatedVector = GetDeviatedVector(MinerWars.AppCode.Game.Gameplay.MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType)); var cannonShotStartPos = GetPosition() + WorldMatrix.Forward * WorldVolume.Radius; cannonShotStartPos = CorrectPosition(cannonShotStartPos, deviatedVector, Parent); // Create and fire missile - but deviate missile direction be random angle MyCannonShots.Add(cannonShotStartPos, forwardVelocity, deviatedVector, usedAmmo, (MySmallShip)Parent); m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds; m_lastSmokePosition = GetSmokePosition(); // We shot one missile return(true); }
private void FireShotGunShot(MyAmmoProperties ammoProperties) { int currentRound = ammoProperties.ProjectileGroupSize; float deviateAngle = ammoProperties.DeviateAngle; // Create one projectile - but deviate projectile direction be random angle if (IsThisGunFriendly()) { deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAnglePlayerOnEnemy; } else { deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAngleEnemyBotOnPlayer; } while (currentRound-- > 0) { Vector3 projectileForwardVector = MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, deviateAngle); float billboardSize = ammoProperties.AmmoType == MyAmmoType.Explosive ? 2 : 1; MyProjectiles.AddShotgun(ammoProperties, Parent, m_positionMuzzleInWorldSpace, Vector3.Zero /* Parent.Physics.LinearVelocity*/, projectileForwardVector, currentRound % MyShotgunConstants.PROJECTILE_GROUP_SIZE == 0, 2, this, billboardSize, Parent); } m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds; AddWeaponCue(ammoProperties.ShotSound); }
// Create smoke and debris particle at the place of voxel/model hit static void CreateEMPHitParticles(ref Vector3 hitPoint, ref Vector3 normal, ref Vector3 direction, MyEntity physObject, MyEntity weapon, MyEntity ownerEntity = null) { Vector3 reflectedDirection = Vector3.Reflect(direction, normal); MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection); MyParticleEffect effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.Hit_EMPAmmo); Matrix dirMatrix = MyMath.MatrixFromDir(reflectedDirection); effect.WorldMatrix = Matrix.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up); }
// Create smoke and debris particle at the place of voxel/model hit static void CreateBasicHitAutocannonParticles(ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MyEntity weapon, float scale, MyEntity ownerEntity = null) { MyParticleEffect effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.Hit_AutocannonBasicAmmo); Vector3 reflectedDirection = Vector3.Reflect(direction, normal); MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection); MatrixD dirMatrix = MatrixD.CreateFromDir(reflectedDirection); effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up); effect.UserScale = scale; }
// Create smoke and debris particle at the place of voxel/model hit static void CreateBasicHitParticles(ref Vector3 hitPoint, ref Vector3 normal, ref Vector3 direction, MyEntity physObject, MyEntity weapon, MyEntity ownerEntity = null) { Vector3 reflectedDirection = Vector3.Reflect(direction, normal); MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection); if (MyCamera.GetDistanceWithFOV(hitPoint) < 200) { MyParticleEffect effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Hit_BasicAmmo); Matrix dirMatrix = MyMath.MatrixFromDir(reflectedDirection); effect.WorldMatrix = Matrix.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up); } }
protected Vector3 GetDeviatedVector(MyAmmoProperties ammoProperties) { float deviateAngle = ammoProperties.DeviateAngle; // Create one projectile - but deviate projectile direction be random angle if (IsThisGunFriendly()) { deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAnglePlayerOnEnemy; } else { deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAngleEnemyBotOnPlayer; } return(MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, deviateAngle)); }
static void CreateBasicHitSmallParticles(ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MyEntity weapon, float scale, MyEntity ownerEntity = null) { Vector3D reflectedDirection = Vector3D.Reflect(direction, normal); MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection); if (MySector.MainCamera.GetDistanceWithFOV(hitPoint) < 100) { MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Hit_BasicAmmoSmall, out effect)) { MatrixD dirMatrix = MatrixD.CreateFromDir(reflectedDirection); effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up); effect.UserScale = scale; } } }
private Vector3 GetTargetPositionByDamageRatio(MySmallShipBot bot) { Vector3 targetPos = m_target.GetPosition(); if (MySession.PlayerShip != null && MyFactions.GetFactionsRelation(bot, MySession.PlayerShip) == MyFactionRelationEnum.Enemy) { Vector3 botPos = bot.GetPosition(); Vector3 botToTarget = targetPos - botPos; Vector3 dir = Vector3.Normalize(botToTarget); float degrees = (float)Math.Pow(120, bot.GetDamageRatio() * 1.5 - 1.2) * 4f; float deviatingAngle = MathHelper.ToRadians(degrees); dir = MyUtilRandomVector3ByDeviatingVector.GetRandom(dir, deviatingAngle); targetPos = botPos + botToTarget.Length() * dir * 3; } return(targetPos); }
protected Vector3 GetDeviatedVector(MyAmmoProperties ammoProperties) { float deviateAngle = ammoProperties.DeviateAngle; // Create one projectile - but deviate projectile direction be random angle if (((Parent as MyGunBase).IsThisGunFriendly() || MyGuiScreenGamePlay.Static.ControlledEntity == (Parent as MyLargeShipGunBase).PrefabParent)) { deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAnglePlayerOnEnemy; } else { deviateAngle += MyGameplayConstants.GameplayDifficultyProfile.DeviatingAngleEnemyLargeWeaponOnPlayer; deviateAngle += GetDeviatedAngleByDamageRatio(); } return(MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, deviateAngle)); }
public static void CreateBasicHitParticles(string effectName, ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MyEntity weapon, float scale, MyEntity ownerEntity = null) { Vector3D reflectedDirection = Vector3D.Reflect(direction, normal); MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection); MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Hit_BasicAmmoSmall, out effect)) { MatrixD dirMatrix = MatrixD.CreateFromDir(normal); effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up); //VRageRender.MyRenderProxy.DebugDrawSphere(hitPoint, 0.1f, Color.Wheat, 1, false); // VRageRender.MyRenderProxy.DebugDrawAxis(effect.WorldMatrix, 5, false); effect.UserScale = scale; } }
public void Explode(MyEntity collideEntity) { if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive) { //make flying shrapnels int shrapnels = MyCannonShotConstants.PROXIMITY_SHRAPNELS_COUNT; while (shrapnels-- > 0) { Vector3 projectileForwardVector = MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward, MathHelper.TwoPi); //MyProjectiles.Add( // MyAmmoConstants.GetAmmoProperties(MyAmmoPropertiesEnum.Shrapnel), //Parent, GetPosition(), Vector3.Zero, projectileForwardVector, false, 3, this); MyProjectiles.Add( MyAmmoConstants.GetAmmoProperties(MyAmmoPropertiesEnum.Shrapnel), Parent, GetPosition(), Vector3.Zero, projectileForwardVector, false, 3, this); } } Explode(); }
// Create smoke and debris particle at the place of voxel/model hit from explosive projectil static void CreateExplosiveHitParticles(ref Vector3 hitPoint, ref Vector3 normal, ref Vector3 direction, MyEntity physObject, MyEntity weapon, MyEntity ownerEntity = null) { if (MyMwcUtils.GetRandomFloat(0.0f, 1.0f) > MyShotgunConstants.EXPLOSIVE_PROJECTILE_RELIABILITY) { //this projectile failed to explode Vector3 reflectedDirection = Vector3.Reflect(direction, normal); MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection); MyParticleEffect effect = GetEffectForWeapon(weapon, (int)MyParticleEffectsIDEnum.Hit_ExplosiveAmmo); Matrix dirMatrix = MyMath.MatrixFromDir(reflectedDirection); effect.WorldMatrix = Matrix.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up); } else { //this projectile exploded MyExplosion newExplosion = MyExplosions.AddExplosion(); if (newExplosion != null) { float radius = MyMwcUtils.GetRandomFloat(5, 20); newExplosion.Start(0, 0, 0, MyExplosionTypeEnum.AMMO_EXPLOSION, new BoundingSphere(hitPoint, radius), 1, MyExplosionForceDirection.EXPLOSION, MyGroupMask.Empty, false, ownerEntity: ownerEntity, hitEntity: physObject); } } }
/// <summary> /// Initialize flares to fire /// </summary> private void FireFlares() { m_flareDeploy = MyAudio.AddCue2dOr3d(this, MySoundCuesEnum.SfxFlareDeploy, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); MyAudio.UpdateCuePosition(m_flareDeploy, GetPosition(), GetForward(), GetUp(), Physics.LinearVelocity); foreach (FlareParticle particle in m_particles) { particle.Position = WorldMatrix.Translation; Matrix rot = Matrix.CreateFromAxisAngle(WorldMatrix.Forward, MyMwcUtils.GetRandomFloat(0.0f, MathHelper.TwoPi)); particle.Dir = Vector3.TransformNormal(MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Up, 0.2f), rot); particle.FlyTime = MyMwcUtils.GetRandomFloat(500, 8000); particle.Life = MyMwcUtils.GetRandomFloat(8000, MyDecoyFlareConstants.MAX_LIVING_TIME); var effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.UniversalLauncher_DecoyFlare); effect.UserBirthMultiplier = 0.3f; particle.ParticleEffect = effect; } m_startParticleTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; m_flaresFired = true; }
public Vector3 GetDeviatedVector(float deviateAngle, Vector3 direction) { return(MyUtilRandomVector3ByDeviatingVector.GetRandom(direction, deviateAngle)); }
// Every child of this base class must implement Shot() method, which shots projectile or missile. // Method returns true if something was shot. False if not (because interval between two shots didn't pass) public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo) { LastShotId = null; float missileLauncherShotInterval = float.MaxValue; switch (usedAmmo.AmmoType) { case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_BioChem: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_EMP: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Engine_Detection: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Radar_Detection: case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Visual_Detection: missileLauncherShotInterval = MyGuidedMissileConstants.MISSILE_LAUNCHER_SHOT_INTERVAL_IN_MILISECONDS; break; default: throw new ArgumentOutOfRangeException(); } if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileLauncherShotInterval && !IsDummy) { return(false); } // Throw ship backward (by deviated vector) this.Parent.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, MyUtilRandomVector3ByDeviatingVector.GetRandom(Vector3.Backward, MathHelper.ToRadians(5)) * MyMwcUtils.GetRandomFloat(40000, 50000), null, null); // Play missile launch cue (one-time) AddWeaponCue(MySoundCuesEnum.WepMissileLaunch3d); Vector3 forwardVelocity = MyMath.ForwardVectorProjection(this.WorldMatrix.Forward, GetParentMinerShip().Physics.LinearVelocity); // Create and fire missile - but deviate missile direction be random angle Vector3 deviatedVector = GetDeviatedVector(MinerWars.AppCode.Game.Gameplay.MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType)); // correct missile start position if it would intersect some entity Vector3 missileStartPosition = m_positionMuzzleInWorldSpace; missileStartPosition = CorrectPosition(missileStartPosition, deviatedVector, Parent); if (MinerWars.AppCode.Game.Managers.Session.MySession.Static.Is2DSector) { forwardVelocity.Y = 0; deviatedVector.Y = 0; } var missile = MyMissiles.Add(usedAmmo.AmmoType, missileStartPosition, forwardVelocity, deviatedVector, LocalMatrix.Translation, Parent, ((MySmallShip)Parent).TargetEntity, isDummy: this.IsDummy); if (missile != null) { missile.EntityId = MyEntityIdentifier.AllocateId(); MyEntityIdentifier.AddEntityWithId(missile); LastShotId = missile.EntityId; GetParentMinerShip().LastMissileFired = missile; } //MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds; m_lastSmokePosition = GetSmokePosition(); if (SysUtils.MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE) { MinerWars.AppCode.Game.Trailer.MyTrailerSave.UpdateGunShot(this.Parent, Trailer.MyTrailerGunsShotTypeEnum.MISSILE); } // We shot one missile return(true); }