/// <summary> /// Called on some contact start with this entity. /// </summary> /// <param name="contactInfo">The contact info.</param> protected override void OnContactStart(MyContactEventInfo contactInfo) { MyEntity collidedEntity = contactInfo.GetOtherEntity(this); Debug.Assert(!collidedEntity.Closed); MyMissile missile = collidedEntity as MyMissile; if ((missile != null) && (OwnerEntity == missile.OwnerEntity)) { //We have hit another missile of ours return; } if (collidedEntity is MySmallShip && OwnerEntity == MySession.PlayerShip && MySession.PlayerFriends.Contains(collidedEntity as MySmallShip)) { //missiles wont hit out friends return; } base.OnContactStart(contactInfo); m_collidedEntity = collidedEntity; m_collidedEntity.OnClose += m_collidedEntity_OnClose; m_collisionPoint = contactInfo.m_ContactPoint; if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && m_collidedEntity is MyStaticAsteroid && !m_collidedEntity.IsDestructible) { HUD.MyHud.ShowIndestructableAsteroidNotification(); } Explode(); }
protected override void OnContactStart(MyContactEventInfo contactInfo) { if (!m_directionAfterContact.HasValue) { base.OnContactStart(contactInfo); var entityA = ((MyPhysicsBody)contactInfo.m_RigidBody1.m_UserData).Entity; var entityB = ((MyPhysicsBody)contactInfo.m_RigidBody2.m_UserData).Entity; var otherEntity = entityA == this ? entityB : entityA; var voxelMap = otherEntity as MyVoxelMap; Vector3 position; Vector3 normal; if (voxelMap != null) { var line = new MyLine(this.GetPosition(), this.GetPosition() + DISTANCE_TO_TEST_VOXEL_INTERSECTION * this.GetForward()); MyIntersectionResultLineTriangleEx?intersectionResult; var intersected = voxelMap.GetIntersectionWithLine(ref line, out intersectionResult); //Debug.Assert(intersected); //Debug.Assert(intersectionResult != null); if (intersectionResult != null) { normal = intersectionResult.Value.NormalInWorldSpace; position = intersectionResult.Value.IntersectionPointInWorldSpace - this.WorldVolume.Radius * 0.5f * normal; } else { normal = -contactInfo.m_ContactNormal; position = GetPosition() + this.WorldVolume.Radius * 0.5f * normal; } } else { normal = -contactInfo.m_ContactNormal; position = GetPosition() + this.WorldVolume.Radius * 0.5f * normal; } Physics.LinearVelocity = Vector3.Zero; Vector3 upVector; MyUtils.GetPerpendicularVector(ref normal, out upVector); m_directionAfterContact = normal; this.MoveAndRotate(position, Matrix.CreateWorld(position, m_directionAfterContact.Value, upVector)); Physics.Static = true; m_matrixAfterContact = WorldMatrix; m_elevation = 0; m_azimuth = 0; } }
/// <summary> /// Gets the other entity from contact. /// </summary> /// <param name="eventInfo">The event info.</param> /// <param name="sourceEntity">Entity that we knows and for wich we want opposite entity.</param> /// <returns></returns> internal static MyEntity GetOtherEntity(this MyContactEventInfo eventInfo, MyEntity sourceEntity) { MyPhysicsBody ps1 = (MyPhysicsBody)eventInfo.m_RigidBody1.m_UserData; MyPhysicsBody ps2 = (MyPhysicsBody)eventInfo.m_RigidBody2.m_UserData; if (ps1.Entity == sourceEntity) { return(ps2.Entity); } return(ps1.Entity); }
protected override void OnContactStart(MyContactEventInfo contactInfo) { MyPhysicsBody ps1 = (MyPhysicsBody)contactInfo.m_RigidBody1.m_UserData; MyPhysicsBody ps2 = (MyPhysicsBody)contactInfo.m_RigidBody2.m_UserData; if (ps1.Entity is MyExplosionDebrisBase && ps2.Entity is MyExplosionDebrisBase) { MyCommonDebugUtils.AssertDebug(false); } base.OnContactStart(contactInfo); }
protected override void OnContactStart(MyContactEventInfo contactInfo) { base.OnContactStart(contactInfo); m_collidedEntity = contactInfo.GetOtherEntity(this); if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && m_collidedEntity is MyStaticAsteroid && !m_collidedEntity.IsDestructible) { HUD.MyHud.ShowIndestructableAsteroidNotification(); } Explode(); }
/// <summary> /// Called on some contact with this entity. /// </summary> /// <param name="contactInfo">The contact info.</param> protected override void OnContactStart(MyContactEventInfo contactInfo) { base.OnContactStart(contactInfo); var collidedEntity = contactInfo.GetOtherEntity(this); /* * if (IsExploded || contactInfo.GetOtherEntity(this) != m_collidedEntity || m_wasPenetration) * { * return; * } */ /* * if (Vector3.Dot(WorldMatrix.Forward, contactInfo.m_ContactNormal) < MyMissileConstants.MISSILE_MINIMAL_HIT_DOT) * { * //Hit wasnt facing the target, just slide or something * return; * } */ if (collidedEntity is MySmallShip && OwnerEntity == MySession.PlayerShip && MySession.PlayerFriends.Contains(collidedEntity as MySmallShip)) { //missiles wont hit out friends return; } m_collidedEntity = collidedEntity; m_collidedEntity.OnClose += m_collidedEntityClosedHandler; m_collisionPoint = contactInfo.m_ContactPoint; if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && m_collidedEntity is MyStaticAsteroid && !m_collidedEntity.IsDestructible) { HUD.MyHud.ShowIndestructableAsteroidNotification(); } /* * if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster) * { * if (m_collidedEntity is MyVoxelMap) * { * return; * } * } */ Explode(m_collidedEntity); }
protected override void OnContactStart(MyContactEventInfo contactInfo) { base.OnContactStart(contactInfo); if (m_state == MyCurrentState.ACTIVATED) { m_collidedEntity = contactInfo.GetOtherEntity(this); if (m_collidedEntity is MySmallShip && MyFactions.GetFactionsRelation(this, m_collidedEntity) == MyFactionRelationEnum.Enemy) { if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && m_collidedEntity is MyStaticAsteroid && !m_collidedEntity.IsDestructible) { HUD.MyHud.ShowIndestructableAsteroidNotification(); } // Create explosion and close; Explode(); } } }
protected override void OnContactStart(MyContactEventInfo contactInfo) { var collidedEntity = contactInfo.GetOtherEntity(this); if (!(collidedEntity is MyMeteor)) { MyParticleEffect pe = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Explosion_Meteor); pe.WorldMatrix = this.WorldMatrix; pe.UserScale = this.m_size * 0.01f; MyExplosion newExplosion = MyExplosions.AddExplosion(); MyExplosionInfo info = new MyExplosionInfo() { PlayerDamage = 100, Damage = 100, EmpDamage = 0, ExplosionType = MyExplosionTypeEnum.METEOR_EXPLOSION, ExplosionSphere = new BoundingSphere(GetPosition(), m_size), LifespanMiliseconds = MyExplosionsConstants.EXPLOSION_LIFESPAN, ParticleScale = 1, OwnerEntity = this, HitEntity = collidedEntity, ExplosionFlags = MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DEBRIS /*| MyExplosionFlags.FORCE_DEBRIS*/, PlaySound = true, VoxelCutoutScale = 1, VoxelExplosionCenter = GetPosition() }; if (newExplosion != null) { newExplosion.Start(ref info); } this.MarkForClose(); } }
/// <summary> /// Called when [contact touch]. /// </summary> /// <param name="contactInfo">The contact info.</param> public virtual void OnContactTouch(MyContactEventInfo contactInfo) { this.Entity.NotifyContactTouch(contactInfo); }
/// <summary> /// Called when [contact start]. /// </summary> /// <param name="contactInfo">The contact info.</param> public virtual void OnContactStart(MyContactEventInfo contactInfo) { // Notify entity(script) about contact. this.Entity.NotifyContactStart(contactInfo); }