public virtual void Roam() { LookDirection = new TGCVector3(LookDirection.X, 0, LookDirection.Z); // Elimino la componente Y para que roamee al nivel que esta del agua timeSinceLastDirection += GameInstance.ElapsedTime; TGCVector3 rotationVector = TGCVector3.Empty; if (timeSinceLastDirection > timeToChangeDirection) { timeSinceLastDirection = 0f; timeToChangeDirection = MathExtended.GetRandomNumberBetween(2, 5); float randomX = MathExtended.GetRandomNumberBetween(-100, 100); float randomZ = MathExtended.GetRandomNumberBetween(-100, 100); TGCVector3 lastDirection = LookDirection; LookDirection = TGCVector3.Normalize(new TGCVector3(randomX, LookDirection.Y, randomZ)); float angle = MathExtended.AngleBetween(new TGCVector2(lastDirection.X, lastDirection.Z), new TGCVector2(LookDirection.X, LookDirection.Z)); rotationVector.Y = -angle; } rotation += rotationVector; Position += LookDirection * roamingSpeed * GameInstance.ElapsedTime; TGCMatrix rot = TGCMatrix.RotationY(rotation.Y); TGCMatrix trans = TGCMatrix.Translation(Position); TGCMatrix scal = TGCMatrix.Scaling(scale); Transform = scal * rot * trans; }
public Fish(Subnautica gameInstance, string name, List <TgcMesh> meshes, TGCVector3 spawnLocation) : base(gameInstance, name, meshes, 10, 50f) { CollisionStatus = Utils.ECollisionStatus.NOT_COLLISIONABLE; Position = spawnLocation; size = MathExtended.GetRandomNumberBetween(3, 20); scale = TGCVector3.One * size; // LIVING_NPC dropsProbability[ItemDatabase.Instance.Generate(EItemID.RAW_FISH)] = 100; dropsProbability[ItemDatabase.Instance.Generate(EItemID.FISH_SCALE)] = 50; }
private void UpdateParticleEmitter() { timeSinceLastBubblesReposition += ElapsedTime; if (timeSinceLastBubblesReposition >= bubblesRepositionCooldown) { int relativeXPosition = MathExtended.GetRandomNumberBetween(-600, 600); int relativeYPosition = MathExtended.GetRandomNumberBetween(-100, 300); int relativeZPosition = MathExtended.GetRandomNumberBetween(700, 2000); TGCVector3 particlesRelativePosition = Player.RelativeRightDirection * relativeXPosition + Player.RelativeUpDirection * relativeYPosition + Player.LookDirection * relativeZPosition; bubbleParticleEmitter.Position = Player.Position + particlesRelativePosition; timeSinceLastBubblesReposition = 0f; } }
private void Chase() { LookDirection = TGCVector3.Normalize(GameInstance.Player.Position - Position); TGCVector3 rotationAxis = TGCVector3.Cross(InitialLookDirection, LookDirection); // Ojo el orden - no es conmutativo TGCQuaternion rotationQuat = TGCQuaternion.RotationAxis(rotationAxis, MathExtended.AngleBetween(InitialLookDirection, LookDirection)); TGCVector3 nextPosition = Position + LookDirection * chasingSpeed * GameInstance.ElapsedTime; TGCMatrix translationMatrix = TGCMatrix.Translation(nextPosition); TGCMatrix rotationMatrix = TGCMatrix.RotationTGCQuaternion(rotationQuat); TGCMatrix nextTransform = rotationMatrix * translationMatrix; SimulateAndSetTransformation(nextPosition, nextTransform); }
public override void Interact(Player interactor) { AddHealth(-1 * interactor.AttackDamage); GameInstance.OnHitNpcSounds[MathExtended.GetRandomNumberBetween(0, GameInstance.OnHitNpcSounds.Count)].play(); if (!IsAlive) { foreach (Item item in dropsProbability.Keys) { if (dropsProbability[item] > MathExtended.GetRandomNumberBetween(0, 100)) { interactor.CollectItem(item); } } Destroy(); } }
private void CrearObjetosEnElEscenario(CustomVertex.PositionNormalTextured[] vertices) { Random random = new Random(); int posicionesTotales = vertices.Length; // Le resto 2 para que no tener en cuenta los bordes del mapa int posicionesASaltear = 1; // Este valor se cambia adentro del for con un random int minSalto = 1; // Valores para usar en el next del random para saltear int maxSalto = 9; for (int i = verticesWidth; i < posicionesTotales; i += posicionesASaltear) { CustomVertex.PositionNormalTextured verticeActual = vertices[i]; TGCVector3 rotation = TGCVector3.Up * random.Next(10); int scale = random.Next(10, 30); TGCVector3 position = MathExtended.Vector3ToTGCVector3(verticeActual.Position); TgcMesh mesh = meshesPlantas[random.Next(meshesPlantas.Count)]; //GameInstance.InstanceObject(new Collectable(GameInstance, "coral", new List<TgcMesh>(new TgcMesh[] { mesh.createMeshInstance("coral") }), position, scale, rotation, Items.EItemID.CORAL_PIECE)); GameInstance.InstanceStaticSceneObject(new Collectable(GameInstance, "coral", new List <TgcMesh>(new TgcMesh[] { mesh.createMeshInstance("coral") }), position, scale, rotation, Items.EItemID.CORAL_PIECE)); posicionesASaltear = random.Next(minSalto, maxSalto); } }