public override void UpdateAfterSimulation100() { if ((MySector.MainCamera.Position - PositionComp.GetPosition()).AbsMax() > MaxLightUpdateDistance) { NeedsUpdate &= ~MyEntityUpdateEnum.EACH_FRAME; return; } bool needsUpdateEveryFrame = false; needsUpdateEveryFrame |= m_blinkIntervalSeconds > 0; needsUpdateEveryFrame |= GetNewLightPower() != Render.CurrentLightPower; if (needsUpdateEveryFrame) { NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; } else { NeedsUpdate &= ~MyEntityUpdateEnum.EACH_FRAME; } UpdateLightProperties(); }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); if (SafeConstraint != null) { if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_CONNECTORS_AND_MERGE_BLOCKS && CustomName.ToString() == "DEBUG") { DebugDrawInfo(new Vector2(0.0f, 0.0f)); m_other.DebugDrawInfo(new Vector2(0.0f, 120.0f)); MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_right) * 10.0f, Color.Red, Color.Red, false); MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight) * 10.0f, Color.Red, Color.Red, false); MyRenderProxy.DebugDrawLine3D(PositionComp.GetPosition(), PositionComp.GetPosition() + WorldMatrix.GetDirectionVector(m_otherRight) * 5.0f, Color.Yellow, Color.Yellow, false); MyRenderProxy.DebugDrawLine3D(m_other.PositionComp.GetPosition(), m_other.PositionComp.GetPosition() + m_other.WorldMatrix.GetDirectionVector(m_other.m_right) * 5.0f, Color.Yellow, Color.Yellow, false); } Vector3 thisVelocity = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition()); Vector3 otherVelocity = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition()); Vector3 relativeVelocity = otherVelocity - thisVelocity; // Damping to avoid too quick approach if (relativeVelocity.Length() > 0.5f) { CubeGrid.Physics.LinearVelocity += relativeVelocity * 0.05f; m_other.CubeGrid.Physics.LinearVelocity -= relativeVelocity * 0.05f; } } }
// This method initializes voxel map (size, position, etc) but doesn't load voxels // It only presets all materials to values specified in 'defaultMaterial' - so it will become material everywhere. protected virtual void InitVoxelMap(MatrixD worldMatrix, Vector3I size, bool useOffset = true) { ProfilerShort.Begin("InitVoxelMap"); NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; var defaultMaterial = MyDefinitionManager.Static.GetDefaultVoxelMaterialDefinition(); SizeInMetres = size * MyVoxelConstants.VOXEL_SIZE_IN_METRES; SizeInMetresHalf = SizeInMetres / 2.0f; PositionComp.LocalAABB = new BoundingBox(-SizeInMetresHalf, SizeInMetresHalf); if (MyPerGameSettings.OffsetVoxelMapByHalfVoxel && useOffset) { worldMatrix.Translation += MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF; PositionLeftBottomCorner += MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF; } PositionComp.SetWorldMatrix(worldMatrix); /*Debug.Assert((Size.X & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); * Debug.Assert((Size.Y & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); * Debug.Assert((Size.Z & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); * * Debug.Assert((Size.X % MyVoxelCoordSystems.RenderCellSizeInLodVoxels(0)) == 0); * Debug.Assert((Size.Y % MyVoxelCoordSystems.RenderCellSizeInLodVoxels(0)) == 0); * Debug.Assert((Size.Z % MyVoxelCoordSystems.RenderCellSizeInLodVoxels(0)) == 0);*/ ContentChanged = false; ProfilerShort.End(); }
public void Shoot(MyShootActionEnum action, Vector3 direction, string gunAction) { // Angle of muzzle flash particle m_muzzleFlashLength = MyUtils.GetRandomFloat(3, 4); // *m_barrel.GetMuzzleSize(); m_muzzleFlashRadius = MyUtils.GetRandomFloat(0.9f, 1.5f); // *m_barrel.GetMuzzleSize(); // Increase count of smokes to draw SmokesToGenerateIncrease(); // Plays sound StartLoopSound(); VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyAutocannonGun.Shot add projectile"); m_gunBase.Shoot(Parent.Physics.LinearVelocity); m_gunBase.ConsumeAmmo(); //VRageRender.MyRenderProxy.DebugDrawSphere(GetPosition(), 0.1f, Vector3.One, 1, false); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); if (BackkickForcePerSecond > 0) { CubeGrid.Physics.AddForce( MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, -direction * BackkickForcePerSecond, PositionComp.GetPosition(), null); } m_cannonMotorEndPlayed = false; m_lastTimeShoot = MySandboxGame.TotalGamePlayTimeInMilliseconds; }
public void DrawHud(IMyCameraController camera, long playerId) { ProfilerShort.Begin("Can shoot"); MyGunStatusEnum status; CanShoot(MyShootActionEnum.PrimaryAction, playerId, out status); ProfilerShort.End(); if (status == MyGunStatusEnum.OK || status == MyGunStatusEnum.Cooldown) { var from = PositionComp.GetPosition() + PositionComp.WorldMatrix.Forward; var to = PositionComp.GetPosition() + 50 * PositionComp.WorldMatrix.Forward; Vector3D target = Vector3D.Zero; if (MyHudCrosshair.GetTarget(from, to, ref target)) { float distance = (float)Vector3D.Distance(MySector.MainCamera.Position, target); MyTransparentGeometry.AddBillboardOriented( "RedDot", Vector4.One, target, MySector.MainCamera.LeftVector, MySector.MainCamera.UpVector, distance / 300.0f); } } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); if ((MySector.MainCamera.Position - PositionComp.GetPosition()).AbsMax() > MaxLightUpdateDistance) { return; } float newLightPower = MathHelper.Clamp(Render.CurrentLightPower + (IsWorking ? 1 : -1) * m_lightTurningOnSpeed, 0, 1); if (newLightPower != Render.CurrentLightPower) { Render.CurrentLightPower = newLightPower; bool on = newLightPower > 0; m_light.ReflectorOn = on; m_light.LightOn = on; m_light.GlareOn = on; UpdateIntensity(); } UpdateLightBlink(); UpdateLightPosition(); UpdateLightProperties(); UpdateEmissivity(false); }
// This method initializes voxel map (size, position, etc) but doesn't load voxels // It only presets all materials to values specified in 'defaultMaterial' - so it will become material everywhere. virtual protected void InitVoxelMap(Vector3D positionMinCorner, Vector3I size, bool useOffset = true) { NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; var defaultMaterial = MyDefinitionManager.Static.GetDefaultVoxelMaterialDefinition(); SizeInMetres = size * MyVoxelConstants.VOXEL_SIZE_IN_METRES; SizeInMetresHalf = SizeInMetres / 2.0f; PositionComp.LocalAABB = new BoundingBox(-SizeInMetresHalf, SizeInMetresHalf); if (MyPerGameSettings.OffsetVoxelMapByHalfVoxel && useOffset) { positionMinCorner += MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF; } PositionLeftBottomCorner = positionMinCorner; PositionComp.SetWorldMatrix(MatrixD.CreateTranslation(PositionLeftBottomCorner + SizeInMetresHalf)); // Voxel map size must be multiple of a voxel data cell size. MyDebug.AssertRelease((Size.X & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); MyDebug.AssertRelease((Size.Y & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); MyDebug.AssertRelease((Size.Z & MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS_MASK) == 0); // Voxel map size must be multiple of a voxel data cell size. MyDebug.AssertRelease((Size.X % MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS) == 0); MyDebug.AssertRelease((Size.Y % MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS) == 0); MyDebug.AssertRelease((Size.Z % MyVoxelConstants.RENDER_CELL_SIZE_IN_VOXELS) == 0); }
protected virtual void ClampToWorld() { var resPosition = PositionComp.GetPosition(); float offset = 10; if (resPosition.X > MySession.Static.WorldBoundaries.Max.X) { resPosition.X = MySession.Static.WorldBoundaries.Max.X - offset; } else if (resPosition.X < MySession.Static.WorldBoundaries.Min.X) { resPosition.X = MySession.Static.WorldBoundaries.Min.X + offset; } if (resPosition.Y > MySession.Static.WorldBoundaries.Max.Y) { resPosition.Y = MySession.Static.WorldBoundaries.Max.Y - offset; } else if (resPosition.Y < MySession.Static.WorldBoundaries.Min.Y) { resPosition.Y = MySession.Static.WorldBoundaries.Min.Y + offset; } if (resPosition.Z > MySession.Static.WorldBoundaries.Max.Z) { resPosition.Z = MySession.Static.WorldBoundaries.Max.Z - offset; } else if (resPosition.Z < MySession.Static.WorldBoundaries.Min.Z) { resPosition.Z = MySession.Static.WorldBoundaries.Min.Z + offset; } PositionComp.SetPosition(resPosition); }
private void UpdateLightPosition() { if (m_light == null || !m_positionDirty) { return; } ProfilerShort.Begin("UpdateLightPosition"); m_positionDirty = false; var newPos = PositionComp.GetPosition() + Vector3.TransformNormal(m_lightLocalPosition, WorldMatrix); if (Vector3D.DistanceSquared(m_lightWorldPosition, newPos) > MIN_MOVEMENT_SQUARED_FOR_UPDATE) { m_lightWorldPosition = newPos; // seems unnecessary, as we are already updating position //m_light.MarkPositionDirty(); } m_light.ParentID = Render.GetRenderObjectID(); MatrixD toLocal = PositionComp.WorldMatrixNormalizedInv; m_light.Position = Vector3D.Transform(m_lightWorldPosition, toLocal); m_light.ReflectorDirection = Vector3D.TransformNormal(WorldMatrix.Forward, toLocal); m_light.ReflectorUp = Vector3D.TransformNormal(WorldMatrix.Right, toLocal); ProfilerShort.End(); }
public string RaycastDetectors(Vector3 worldFrom, Vector3 worldTo) { var invWorld = PositionComp.GetWorldMatrixNormalizedInv(); var from = Vector3.Transform(worldFrom, invWorld); var to = Vector3.Transform(worldTo, invWorld); BoundingBox unit = new BoundingBox(-Vector3.One, Vector3.One); Vector3 localFrom, localTo; string result = null; float distance = float.MaxValue; foreach (var group in m_detectors) { foreach (var det in group.Value) { localFrom = Vector3.Transform(from, det); localTo = Vector3.Transform(to, det); float?dist = unit.Intersects(new Ray(localFrom, localTo)); if (dist.HasValue && dist.Value < distance) { distance = dist.Value; result = group.Key; } } } return(result); }
public override List <MyHudEntityParams> GetHudParams(bool allowBlink) { CustomNameWithFaction.Clear(); if (!string.IsNullOrEmpty(GetOwnerFactionTag())) { CustomNameWithFaction.Append(GetOwnerFactionTag()); CustomNameWithFaction.Append("."); } CustomNameWithFaction.AppendStringBuilder(CustomName); m_hudParams.Clear(); m_hudParams.Add(new MyHudEntityParams() { FlagsEnum = MyHudIndicatorFlagsEnum.SHOW_ALL, Text = CustomNameWithFaction, OffsetText = true, TargetMode = GetPlayerRelationToOwner(), Entity = this, Parent = CubeGrid, RelativePosition = Vector3.Transform(PositionComp.GetPosition(), CubeGrid.PositionComp.WorldMatrixNormalizedInv), BlinkingTime = allowBlink && IsBeingHacked ? MyGridConstants.HACKING_INDICATION_TIME_MS / 1000 : 0 }); return(m_hudParams); }
public override void OnDestroy() { MySoundPair cueEnum = BlockDefinition.ActionSound; if (cueEnum != MySoundPair.Empty) { MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter(); if (emitter != null) { emitter.Entity = this; emitter.SetPosition(PositionComp.GetPosition()); emitter.PlaySound(cueEnum); } } if (Sandbox.Game.Multiplayer.Sync.IsServer) { if (!IsFunctional) { return; } if (m_damageType == MyDamageType.Bullet) { Explode(); } else { MarkForExplosion(); ExplodeDelayed(500); } } }
private void UpdateLightPosition() { if (m_light == null || !m_positionDirty) { return; } ProfilerShort.Begin("UpdateLightPosition"); var newPos = PositionComp.GetPosition() + Vector3.TransformNormal(m_lightLocalPosition, WorldMatrix); if (Vector3D.DistanceSquared(m_lightWorldPosition, newPos) > 0.0001) { m_lightWorldPosition = newPos; m_light.MarkPositionDirty(); } m_light.ParentID = Render.GetRenderObjectID(); MatrixD toLocal = PositionComp.WorldMatrixNormalizedInv; m_light.Position = Vector3D.Transform(m_lightWorldPosition, toLocal); m_light.ReflectorDirection = Vector3D.TransformNormal(WorldMatrix.Forward, toLocal); m_light.ReflectorUp = Vector3D.TransformNormal(WorldMatrix.Up, toLocal); m_light.MarkPropertiesDirty(); m_positionDirty = false; ProfilerShort.End(); }
private void CalculateMergeData(ref MergeData data) { var mergeBlockDefinition = this.BlockDefinition as MyMergeBlockDefinition; float maxStrength = mergeBlockDefinition != null ? mergeBlockDefinition.Strength : 0.1f; data.Distance = (float)(WorldMatrix.Translation - m_other.WorldMatrix.Translation).Length() - CubeGrid.GridSize; data.StrengthFactor = (float)Math.Exp(-data.Distance / CubeGrid.GridSize); // Debug.Assert(x <= 1.0f); // This is not so important, but testers kept reporting it, so let's leave it commented out :-) float strength = MathHelper.Lerp(0.0f, maxStrength * (CubeGrid.GridSizeEnum == MyCubeSize.Large ? 0.005f : 0.1f), data.StrengthFactor); // 0.005 for large grid, 0.1 for small grid!? Vector3 thisVelocity = CubeGrid.Physics.GetVelocityAtPoint(PositionComp.GetPosition()); Vector3 otherVelocity = m_other.CubeGrid.Physics.GetVelocityAtPoint(m_other.PositionComp.GetPosition()); data.RelativeVelocity = otherVelocity - thisVelocity; float velocityFactor = 1.0f; // The quicker the ships move towards each other, the weaker the constraint strength float rvLength = data.RelativeVelocity.Length(); velocityFactor = Math.Max(3.6f / (rvLength > 0.1f ? rvLength : 0.1f), 1.0f); data.ConstraintStrength = strength / velocityFactor; Vector3 toOther = m_other.PositionComp.GetPosition() - PositionComp.GetPosition(); Vector3 forward = WorldMatrix.GetDirectionVector(m_forward); data.Distance = (toOther).Length(); data.PositionOk = data.Distance < CubeGrid.GridSize + 0.17f; // 17 cm is tested working value. 15 cm was too few data.AxisDelta = (float)(forward + m_other.WorldMatrix.GetDirectionVector(m_forward)).Length(); data.AxisOk = data.AxisDelta < 0.1f; data.RotationDelta = (float)(WorldMatrix.GetDirectionVector(m_right) - m_other.WorldMatrix.GetDirectionVector(m_other.m_otherRight)).Length(); data.RotationOk = data.RotationDelta < 0.08f; }
public void TrajectoryModifier(PositionComp rotComp, double value) { const float R = 50f; const double F = 0.1; double t = value; rotComp.Position2D = new Vector2((float)(R * Math.Sin(MathHelper.TwoPi * F * t)), (float)(R * Math.Cos(MathHelper.TwoPi * F * t))); }
void MarkForExplosion() { m_marked = true; //Large grid = 12.5m radius of block //Small grid = 2.5m radius float radiusMultiplier = 4; //reduced by 20% float warheadBlockRadius = CubeGrid.GridSize * radiusMultiplier; float shrink = 0.85f; m_explosionShrinkenSphere = new BoundingSphereD(PositionComp.GetPosition(), (double)warheadBlockRadius * shrink); m_explosionParticleSphere = new BoundingSphereD(PositionComp.GetPosition(), double.MinValue); MyGamePruningStructure.GetAllEntitiesInSphere(ref m_explosionShrinkenSphere, m_entitiesInShrinkenSphere); m_warheadsInsideCount = 0; foreach (var entity in m_entitiesInShrinkenSphere) { if (Vector3D.DistanceSquared(PositionComp.GetPosition(), entity.PositionComp.GetPosition()) < warheadBlockRadius * shrink * warheadBlockRadius * shrink) { MyWarhead warhead = entity as MyWarhead; if (warhead != null) { m_warheadsInsideCount++; if (!warhead.MarkedToExplode) { m_explosionParticleSphere = m_explosionParticleSphere.Include(new BoundingSphereD(warhead.PositionComp.GetPosition(), CubeGrid.GridSize * radiusMultiplier + warhead.CubeGrid.GridSize)); } } var block = entity as MyCubeBlock; if (block != null) { block.MarkedToExplode = true; } } } m_entitiesInShrinkenSphere.Clear(); //m_radius += m_warheadsInsideCount * 0.1f; //Explosion radius is based on linear function where 1 warhead has explosion radius : //Large: 22.4415f // Small: 4.4883f //each warhead contribute 0.26 % of radius //explosion is clamped to maxExplosionRadius float fullExplosionRadius = Math.Min(m_maxExplosionRadius, (1 + 0.024f * m_warheadsInsideCount) * m_warheadDefinition.ExplosionRadius); //fullExplosionRadius = fullExplosionRadius; m_explosionFullSphere = new BoundingSphere(m_explosionParticleSphere.Center, (float)Math.Max(fullExplosionRadius, m_explosionParticleSphere.Radius)); if (MyExplosion.DEBUG_EXPLOSIONS) { MyWarheads.DebugWarheadShrinks.Add(m_explosionShrinkenSphere); MyWarheads.DebugWarheadGroupSpheres.Add(m_explosionFullSphere); float particleRadius = (float)m_explosionParticleSphere.Radius; } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. //<ib.floating> //Physics.RigidBody.Gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(PositionComp.GetPosition()); Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(PositionComp.GetPosition()); if (Physics.RigidBody.GetShape().ShapeType == HkShapeType.Sphere) { const float w = 0.5f; m_smoothGravity = m_smoothGravity * w + gravity * (1 - w); m_smoothGravityDir = m_smoothGravity; m_smoothGravityDir.Normalize(); bool anySupport = false; foreach (var supportNormal in m_supportNormals) { float cosalpha = supportNormal.Dot(m_smoothGravityDir); const float cosalphaLimit = 0.8f; // +/- 12 Degrees if (cosalpha > cosalphaLimit) { anySupport = true; break; } } m_supportNormals.Clear(); if (anySupport) { //Physics.RigidBody.Gravity = Vector3.Zero; const float limitGravity = 0.01f; if ((Physics.RigidBody.Gravity.Length() > limitGravity)) { Physics.RigidBody.Gravity *= 0.99f; // Decay gravity } } else { Physics.RigidBody.Gravity = m_smoothGravity; } } else { Physics.RigidBody.Gravity = gravity; } if (m_massChangeForCollisions < 1f) { if ((MySession.Static.ElapsedPlayTime.TotalMilliseconds - m_timeFromSpawn.TotalMilliseconds) >= 2000) { m_massChangeForCollisions = 1f; } } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPointForGrid(PositionComp.GetPosition()); Physics.AddForce(Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, Physics.Mass * gravity, Physics.CenterOfMassWorld, null); }
void GetMostEffectiveToolAction(List <MyToolActionDefinition> toolActions, out MyToolActionDefinition?bestAction, out MyToolHitCondition bestCondition) { MyCharacterDetectorComponent detectorComponent = m_owner.Components.Get <MyCharacterDetectorComponent>(); IMyEntity hitEntity = null; uint shapeKey = 0; if (detectorComponent != null) { hitEntity = detectorComponent.DetectedEntity; shapeKey = detectorComponent.ShapeKey; float hitDistance = Vector3.Distance(detectorComponent.HitPosition, PositionComp.GetPosition()); if (hitDistance > m_toolItemDef.HitDistance) { hitEntity = null; } } bestAction = null; bestCondition = new MyToolHitCondition(); //Get most effective action foreach (var action in toolActions) { if (action.HitConditions != null) { foreach (var condition in action.HitConditions) { if (condition.EntityType != null) { if (hitEntity != null) { string availableState = GetStateForTarget((MyEntity)hitEntity, shapeKey, condition.Component); if (condition.EntityType.Contains(availableState)) { bestAction = action; bestCondition = condition; return; } } else { continue; } } else { bestAction = action; bestCondition = condition; return; } } } } }
/// <summary> /// Called when [world position changed]. /// </summary> /// <param name="source">The source object that caused this event.</param> private void WorldPositionChanged(object source) { // Update light position if (m_light != null) { m_light.Position = (Vector3)PositionComp.GetPosition(); m_light.Color = Vector4.One; m_light.Range = MyMissileConstants.MISSILE_LIGHT_RANGE; } }
public override void UpdateAfterSimulation100() { base.UpdateAfterSimulation100(); if ((MySector.MainCamera.Position - PositionComp.GetPosition()).AbsMax() > MaxLightUpdateDistance) { return; } m_positionDirty = true; }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // Cannon is rotating while shoting. After that, it will slow-down. float normalizedRotationSpeed = 1.0f - MathHelper.Clamp((float)(MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) / m_rotationTimeout, 0, 1); normalizedRotationSpeed = MathHelper.SmoothStep(0, 1, normalizedRotationSpeed); float rotationAngle = normalizedRotationSpeed * MyGatlingConstants.ROTATION_SPEED_PER_SECOND * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; Matrix worldMatrix = this.PositionComp.WorldMatrix; if (rotationAngle != 0 && m_barrel != null) { m_barrel.PositionComp.LocalMatrix = Matrix.CreateRotationY(rotationAngle) * m_barrel.PositionComp.LocalMatrix; } // Handle 'motor loop and motor end' cues if (m_cannonMotorEndPlayed == false) { if (MySandboxGame.TotalGamePlayTimeInMilliseconds > m_lastTimeShoot + m_gunBase.ReleaseTimeAfterFire) { // Stop 'shooting loop' cue StopLoopSound(); m_cannonMotorEndPlayed = true; } } // If gun fires too much, we start generating smokes at the muzzle if ((MySandboxGame.TotalGamePlayTimeInMilliseconds - m_smokeLastTime) >= (MyGatlingConstants.SMOKES_INTERVAL_IN_MILISECONDS)) { m_smokeLastTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; SmokesToGenerateDecrease(); if (m_smokesToGenerate > 0 && m_smokeEffect == null) { if (MySector.MainCamera.GetDistanceWithFOV(PositionComp.GetPosition()) < 150) { if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Autocannon, out m_smokeEffect)) { m_smokeEffect.WorldMatrix = PositionComp.WorldMatrix; m_smokeEffect.OnDelete += new EventHandler(m_smokeEffect_OnDelete); } } } } if (m_smokeEffect != null) { m_smokeEffect.WorldMatrix = MatrixD.CreateTranslation(m_gunBase.GetMuzzleWorldPosition()); m_smokeEffect.UserBirthMultiplier = m_smokesToGenerate; } }
private void UpdateLightPosition() { if (m_light != null) { m_light.Position = PositionComp.GetPosition() + Vector3.TransformNormal(m_lightPositionOffset, PositionComp.WorldMatrix); if (!AnimationRunning) { m_light.UpdateLight(); } } }
public override bool Init() { player = engine.GetPlayer(); pc = player.GetComponent <PositionComp>(); tc = player.GetComponent <TargetComp>(); sfc = player.GetComponent <ShipFittingsComp>(); crosshairComp = player.GetComponent <TrackingCrosshairComp>(); cam = Camera.main; //UICam = GameObject.Find("CameraUI").GetComponent<Camera>(); //uiRoot = GameObject.Find("UIRoot").GetComponent<UIRoot>(); return(true); }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); if (m_previusPosition != PositionComp.GetPosition()) { m_previusPosition = PositionComp.GetPosition(); foreach (var button in m_buttonsUseObjects) { button.UpdateMarkerPosition(); } } }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (HasLocalPlayerAccess()) { m_oreDetectorComponent.Update(PositionComp.GetPosition()); } else { m_oreDetectorComponent.Clear(); } }
void CreateEventData(NecessaryBuffData nowData) { EventTargetData = nowData; // 位置補完データ作成 PositionComp.Initialize(transform.position - OffsetPos, nowData.Position); // サイズ補完データ作成 SizeComp.Initialize(CameraComp.orthographicSize, nowData.OrthoSize); isEventActive = true; ElapsedTime = 0f; }
public virtual void Init(MyObjectBuilder_EntityBase objectBuilder) { ProfilerShort.Begin("MyEntity.Init(objectBuilder)"); MarkedForClose = false; Closed = false; this.Render.PersistentFlags = MyPersistentEntityFlags2.CastShadows; if (objectBuilder != null) { if (objectBuilder.EntityDefinitionId.HasValue) { DefinitionId = objectBuilder.EntityDefinitionId; InitFromDefinition(objectBuilder, DefinitionId.Value); } if (objectBuilder.PositionAndOrientation.HasValue) { var posAndOrient = objectBuilder.PositionAndOrientation.Value; MatrixD matrix = MatrixD.CreateWorld(posAndOrient.Position, posAndOrient.Forward, posAndOrient.Up); MyUtils.AssertIsValid(matrix); PositionComp.SetWorldMatrix((MatrixD)matrix); if (MyPerGameSettings.LimitedWorld) { ClampToWorld(); } } // Do not copy EntityID if it gets overwritten later. It might // belong to some existing entity that we're making copy of. if (objectBuilder.EntityId != 0) { this.EntityId = objectBuilder.EntityId; } this.Name = objectBuilder.Name; this.Render.PersistentFlags = objectBuilder.PersistentFlags; this.Components.Deserialize(objectBuilder.ComponentContainer); } AllocateEntityID(); this.InScene = false; MyEntities.SetEntityName(this, false); if (SyncFlag) { CreateSync(); } GameLogic.Init(objectBuilder); ProfilerShort.End(); }
private static void CreateLaserInfoPacket(WeaponComp selectedWeapon, PositionComp pc, Vector3 direction) { //laser info packet laser fire type wrong LaserComp lc = (LaserComp)selectedWeapon; lc.laserInfoPacket.TimeToLive = selectedWeapon.AttackRange / selectedWeapon.ProjectileSpeed; lc.laserInfoPacket.fireDirection = direction; lc.laserInfoPacket.StartPosition = pc.transform.TransformPoint( selectedWeapon.fittingAttached.PositionOffset + selectedWeapon.fittingAttached.ProjectileSpawnPositionOffset); lc.laserInfoPacket.OwningActorPos = pc; lc.laserInfoPacket.FiringWeaponComp = selectedWeapon; lc.laserInfoPacket.ProjectileSpeed = selectedWeapon.ProjectileSpeed; //lc.laserInfoPacket.laserFireType = lc.laserInfoPacket.laserFireType; }
private void CreateSmokeEffect() { if (m_smokeEffect == null) { if (MySector.MainCamera.GetDistanceFromPoint(PositionComp.GetPosition()) < 150) { if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Autocannon, out m_smokeEffect)) { m_smokeEffect.WorldMatrix = PositionComp.WorldMatrix; m_smokeEffect.OnDelete += OnSmokeEffectDelete; } } } }