private void GoToTarget(ComponentDirection direction, ComponentVelocity velocity, ComponentPosition position, Vector3 target, float fullSpeed, Vector3 playerPosition) { Vector3 directionBetween = position.Position - target; Vector3 directionGhost = direction.Direction; directionBetween.Y = 0.0f; directionGhost.Y = 0.0f; if (directionBetween.Length < 0.1) { position.Position = target; return; } Vector3 ghostToPlayer = position.Position - playerPosition; ghostToPlayer.Y = 0.0f; float ghostDistance = (float)Math.Sqrt(Math.Pow(ghostToPlayer.X, 2) + Math.Pow(ghostToPlayer.Z, 2)); directionBetween = Vector3.Normalize(directionBetween); directionGhost = Vector3.Normalize(directionGhost); double angleBetween = Math.Atan2(directionBetween.Z, directionBetween.X); double angleGhost = Math.Atan2(directionGhost.Z, directionGhost.X); double angle = RadiansToDegree(angleBetween) - RadiansToDegree(angleGhost); if (angle > 180) { angle = 180 - angle; } else if (angle < -180) { angle = -180 - angle; } if (angle > 10) { direction.DirectionChange = 1 * direction.MaxChange; } else if (angle < -10) { direction.DirectionChange = -1 * direction.MaxChange; } else { direction.Direction = directionBetween; float speed = 1f; if ((position.Position - target).Length < 1) { speed = directionBetween.Length * 0.5f; } if (ghostDistance < fullSpeed) { velocity.Velocity = -1f * speed * velocity.MaxVelocity; } else { velocity.Velocity = -0.5f * speed * velocity.MaxVelocity; } } }
/// <summary> /// Returns the Vector3 velocity of this entity /// </summary> /// <returns></returns> public Vector3 GetVelocity() { List <IComponent> compList = this.Components; ComponentVelocity compVel = (ComponentVelocity)compList[1]; return(compVel.Velocity); }
private void FollowPath(ComponentVelocity vel, ComponentPosition pos) { int p = 0; if (path[p + 1].Position.X == path[p].Position.X) { if (path[p + 1].Position.Y < path[p].Position.Y) { vel.Velocity = new Vector3(0, 0, -droneSpeed); } else { vel.Velocity = new Vector3(0, 0, droneSpeed); } } else if (path[p + 1].Position.Y == path[p].Position.Y) { if (path[p + 1].Position.X < path[p].Position.X) { vel.Velocity = new Vector3(-droneSpeed, 0, 0); } else { vel.Velocity = new Vector3(droneSpeed, 0, 0); } } Vector2 v = new Vector2(pos.Position.X, pos.Position.Z); if (v == path[p + 1].Position) { p++; } }
public void Motion(ComponentVelocity vel, ComponentPosition pos) { pos.Position = pos.Position + vel.Velocity * CoolGameBase.dt; //Console.WriteLine("Position of Drone: " + pos.Position); //Console.WriteLine("Velocity of Drone: " + vel.Velocity); }
private void Input(ComponentVelocity velocity, ComponentDirection direction) { if (input.GetKeyState(Keys.DOWN) > 0) { velocity.Velocity = -(input.GetKeyState(Keys.DOWN) * velocity.MaxVelocity); } else if (input.GetKeyState(Keys.UP) > 0) { velocity.Velocity = input.GetKeyState(Keys.UP) * velocity.MaxVelocity; } else { velocity.Velocity = 0; } if (input.GetKeyState(Keys.LEFT) > 0) { direction.DirectionChange = -(input.GetKeyState(Keys.LEFT) * direction.MaxChange); } else if (input.GetKeyState(Keys.RIGHT) > 0) { direction.DirectionChange = input.GetKeyState(Keys.RIGHT) * direction.MaxChange; } else { direction.DirectionChange = 0; } }
public void OnAction(Entity entity) { if ((entity.Mask & MASK) == MASK) { ComponentTransform transform = entity.transform; ComponentVelocity velocity = entity.GetComponent <ComponentVelocity>(); Motion(transform, velocity); } }
public void Motion(ComponentPosition pPos, ComponentVelocity pVel, ComponentAI pAI, string name) { // Updates the target with the most recent player position if (targetIsPlayer) { pAI.Target = mCamera.Position; } // Checks if the AI has found its target and skips search code for efficency if (RoundVectorPosition(pPos.Position).Xz == pAI.Target.Xz) { return; } // Checks if the AI's target is within map boundaries if (!(pAI.Target.X < (mWidth / 2) && !(pAI.Target.X > (mWidth / 2)) && pAI.Target.Z < (mHeight / 2) && !(pAI.Target.Z > (mHeight / 2)))) { return; } // Makes sure target is in a traversable area if (!Traversable[(int)pAI.Target.Z + (mHeight / 2), (int)pAI.Target.X + (mWidth / 2)]) { return; } if (pAI.Path.Length > 0 && pAI.ogTarget == pAI.Target) { // Path following Vector3 direction = pAI.Path[0] - pPos.Position; pPos.Position += direction * pVel.Veclotiy * deltaTime; } else { // Updates path finding pAI.ogTarget = pAI.Target; pAI.Path = ASPath(RoundVectorPosition(pPos.Position), RoundVectorPosition(pAI.Target)); // Path following if (pAI.Path.Length <= 0) { // Path finding failed return; } Vector3 direction = pAI.Path[0] - pPos.Position; pPos.Position += direction * pVel.Veclotiy * deltaTime; } // Check to see if AI has hit closest point in path and removes it if true so it can follow the next point if (RoundVectorPosition(pPos.Position) == pAI.Path[0]) { pAI.Path = pAI.Path.Skip(1).ToArray(); } }
private void PlayerDetection(ComponentPosition pos, ComponentVelocity vel, AIStates state) { if (state == AIStates.Wandering) { Vector2 AIpos = new Vector2(pos.Position.X, pos.Position.Z); Vector2 v = MyGame.NewCameraPosition - AIpos; float dot = MyGame.DotProduct(v.Normalized(), AIpos.Normalized()); if (dot > 0.7) { droneSpeed = 0.8f; } else { droneSpeed = 0.5f; } } }
public override void OnUpdate(float pDelta) { List <Entity> bullets = (_sceneManager.Scenes["Main"].Entities.FindAll(delegate(Entity e) { return(e.Name.Contains("Bullet") == true); })); foreach (var bullet in bullets) { if (bullet != null) { ComponentPosition position = bullet.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition; ComponentVelocity velocity = bullet.GetComponent(ComponentTypes.COMPONENT_VELOCITY) as ComponentVelocity; position.Position = position.Position + (velocity.Velocity * _bulletSpeed) * pDelta; } } base.OnUpdate(pDelta); }
private void Motion(ComponentVelocity velocity, Control e) { if (e.KeyDown(Key.W)) { velocity.Velocity = new Vector3(0.0f, 0.0f, -10.0f); } else if (e.KeyDown(Key.A)) { velocity.Velocity = new Vector3(-10.0f, 0.0f, 0.0f); } else if (e.KeyDown(Key.S)) { velocity.Velocity = new Vector3(0.0f, 0.0f, 10.0f); } else if (e.KeyDown(Key.D)) { velocity.Velocity = new Vector3(10.0f, 0.0f, 0.0f); } else { velocity.Velocity = new Vector3(0.0f, 0.0f, 0.0f); } }
public void Motion(ComponentVelocity velocityComponent, ComponentPlayerControler contolerComponent) { if (Keyboard.GetState().IsKeyDown(Key.Up)) { velocityComponent.Velocity = up; } if (Keyboard.GetState().IsKeyDown(Key.Down)) { velocityComponent.Velocity = down; } if (Keyboard.GetState().IsKeyDown(Key.Right)) { velocityComponent.Velocity = right; } if (Keyboard.GetState().IsKeyDown(Key.Left)) { velocityComponent.Velocity = left; } if (!Keyboard.GetState().IsAnyKeyDown) { velocityComponent.Velocity = still; } }
public override void OnUpdate(float pDelta) { if ((entity.Mask & MASK) == MASK) { ComponentTargetNode targetNode = entity.GetComponent(ComponentTypes.COMPONENT_TARGET) as ComponentTargetNode; ComponentPosition position = entity.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition; ComponentRotation rotation = entity.GetComponent(ComponentTypes.COMPONENT_ROTATION) as ComponentRotation; ComponentVelocity velocity = entity.GetComponent(ComponentTypes.COMPONENT_VELOCITY) as ComponentVelocity; ComponentSpeedModifier speedMod = entity.GetComponent(ComponentTypes.COMPONENT_SPEEDMOD) as ComponentSpeedModifier; ComponentAudio audio = entity.GetComponent(ComponentTypes.COMPONENT_AUDIO) as ComponentAudio; EnvironmentLocationScript droneLocation = null; List <IComponent> scripts = entity.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is EnvironmentLocationScript) { droneLocation = script.script as EnvironmentLocationScript; } } if (droneState == DroneStateTypes.Idle) { IdleDroneLogic(targetNode, position, rotation, velocity, speedMod, audio, droneLocation, pDelta); } else if (droneState == DroneStateTypes.Aggressive) { AggressiveDroneLogic(targetNode, position, rotation, velocity, speedMod, audio, droneLocation, pDelta); } } else { throw new Exception("Drone doesn't have all required components"); } }
public void Motion(ComponentPosition pPos, ComponentVelocity pVel) { pPos.Position += pVel.Veclotiy * deltaTime; }
public void GhostPlayerCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, ComponentLife healthComponent, string entname, List <Entity> EntList, ComponentAudio faudioComponent) { int test = healthComponent.health(); if (test == 1) { if (entname == "Ghost") { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1) { GameScene.gameInstance.test(); faudioComponent.Start(); } } else { if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1) { GameScene.gameInstance.test(); faudioComponent.Start(); } } } else { if (entname == "Ghost") { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1) { healthComponent.down(); fpositionComponent.Position = new Vector3(0.0f, 0.25f, -29.5f); foreach (Entity x in EntList) { if (x.Name == "Ghost") { List <IComponent> components = x.Components; IComponent GhostpositionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); GhostResest((ComponentPosition)GhostpositionComponent); } } ghostCount = 0; faudioComponent.Start(); } } else { if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1) { healthComponent.down(); positionComponent.Position = new Vector3(0.0f, 0.25f, -29.5f); foreach (Entity x in EntList) { if (x.Name == "Ghost") { List <IComponent> components = x.Components; IComponent GhostpositionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); GhostResest((ComponentPosition)GhostpositionComponent); } } ghostCount = 0; faudioComponent.Start(); } } } }
public void GhostWallCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, string entname) { if (entname == "Ghost") { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1) { if (velocityComponent.Velocity == up) { positionComponent.Position += downfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } else if (velocityComponent.Velocity == down) { positionComponent.Position += upfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } else if (velocityComponent.Velocity == right) { positionComponent.Position += leftfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } else if (velocityComponent.Velocity == left) { positionComponent.Position += rightfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } } } else { if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1) { if (fvelocityComponent.Velocity == up) { fpositionComponent.Position += downfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } else if (fvelocityComponent.Velocity == down) { fpositionComponent.Position += upfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } else if (fvelocityComponent.Velocity == right) { fpositionComponent.Position += leftfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } else if (fvelocityComponent.Velocity == left) { fpositionComponent.Position += rightfix; int test; Random rnd = new Random(); test = rnd.Next(4); switch (test) { case 0: velocityComponent.Velocity = right; break; case 1: velocityComponent.Velocity = left; break; case 2: velocityComponent.Velocity = up; break; case 3: velocityComponent.Velocity = down; break; } } } } }
/// <summary> /// Decide on a new target node to reach (neighbour) /// </summary> private void FindNewTarget(ComponentTargetNode targetNode, ComponentPosition inPos, ComponentVelocity inVel, ComponentRotation inRot) { //Get target nodes neighbouring nodes List <Entity> neighbouringNodes = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_NODE) as ComponentNode).NodeLinks; //Choose new target option int nodeChoice = _random.Next(0, neighbouringNodes.Count); //Set target option targetNode.TargetNode = neighbouringNodes[nodeChoice]; //Calculate new velocity Vector3 position = inPos.Position; Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; inVel.Velocity = -Vector3.Normalize(position - targetPosition); //Calculate new rotation inRot.Rotation = LookAt(position, targetPosition); }
private void AggressiveDroneLogic(ComponentTargetNode targetNode, ComponentPosition inPos, ComponentRotation inRot, ComponentVelocity inVel, ComponentSpeedModifier inSpeed, ComponentAudio inAudio, EnvironmentLocationScript inLoc, float inDelta) { Vector3 playerPosition = (_player.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; EnvironmentLocationScript playerLocation = null; List <IComponent> scripts = _player.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is EnvironmentLocationScript) { playerLocation = script.script as EnvironmentLocationScript; } } _timeSinceTrigger += inDelta; //Once the trigger sound has finished, we changed to the angry sound if (_timeSinceTrigger > 1.1f && _timeSinceTrigger < 1.2f) { inAudio.SetAudioBuffer("angry-woah", true); } //Fastest way to calculate the distance float deltaX = playerPosition.X - inPos.Position.X; float deltaY = playerPosition.Y - inPos.Position.Y; float deltaZ = playerPosition.Z - inPos.Position.Z; double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); Vector3 newPPos = new Vector3(playerPosition.X, inPos.Position.Y, playerPosition.Z); //Calculate new rotation inRot.Rotation = LookAt(inPos.Position, newPPos); if (_targettingPlayer) { inVel.Velocity = -Vector3.Normalize(inPos.Position - playerPosition); //Update position inPos.Position += ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); if (_nodePath.Count != 0) { _targettingPlayer = false; _targettingNodePath = true; targetNode.TargetNode = _nodePath.First(); } } else if (_targettingNodePath) { Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); //Update position inPos.Position += ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); _previousPositions.Add(inPos.Position); if (_previousPositions.Count > 6) { _previousPositions.Remove(_previousPositions.First()); if (CheckIfStuck()) { //Recalculate velocity inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); } } //Distance the drone is going to travel Vector3 travelDistance = ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); //Fastest way to calculate the distance deltaX = targetPosition.X - inPos.Position.X; deltaY = targetPosition.Y - inPos.Position.Y; deltaZ = targetPosition.Z - inPos.Position.Z; double distanceToNode = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); if (travelDistance.Length > distanceToNode) { inPos.Position = targetPosition; } else { inPos.Position += travelDistance; } //If drone reached temporary node position then we target the player again if (targetPosition == inPos.Position) { //If we've reached our target, target player again _nodePath.Remove(_nodePath.First()); if (_nodePath.Count != 0) { targetNode.TargetNode = _nodePath.First(); } else { _targettingPlayer = true; _targettingNodePath = false; } } } //If we're targetting the player, we will see if there are any nodes between myself and the player and target the nodes instead //if (_targettingPlayerAgg) //{ // inVel.Velocity = -Vector3.Normalize(inPos.Position - playerPosition); // //Update position // inPos.Position = inPos.Position + ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); // Tuple<bool, Entity> closestNode = NodeCloserThanPlayer(inPos.Position, newPPos, inLoc); // if (closestNode.Item1) // { // _targettingPlayerAgg = false; // _targettingNodeAgg = true; // targetNode.TargetNode = closestNode.Item2; // Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; // inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); // } //} //If we found nodes between the drone and the player, we will target the node and then retarget the player //if (_targettingNodeAgg) //{ // //Update position // inPos.Position = inPos.Position + ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); // Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; // _previousPositions.Add(inPos.Position); // if (_previousPositions.Count > 6) // { // _previousPositions.Remove(_previousPositions.First()); // if (CheckIfStuck()) // { // //Recalculate velocity // inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); // } // } // //Update position // Vector3 travelDistance = ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); // //Fastest way to calculate the distance // deltaX = targetPosition.X - inPos.Position.X; // deltaY = targetPosition.Y - inPos.Position.Y; // deltaZ = targetPosition.Z - inPos.Position.Z; // double distanceToNode = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); // if (travelDistance.Length > distanceToNode) // { // inPos.Position = targetPosition; // } // else // { // inPos.Position += travelDistance; // } // //If drone reached temporary node position then we target the player again // if (targetPosition == inPos.Position) // { // //If we've reached our target, target player again // _targettingNodeAgg = false; // _targettingPlayerAgg = true; // } //} //If the distance between the player and drone is greater than the range then we change state, or if they are not in the same environment (can't be seen) if (distance > _viewRange && _nodePath.Count == 0 || playerLocation.EnvironmentLocation <= 0) { //Since we can't see the player anymore, we'll find the nearest node in our environment to follow targetNode.TargetNode = FindNearestEnvironmentNode(inPos, inLoc); Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; //Other logic (speed mod change, reset velocity to target node (temp)) inSpeed.SpeedMod = 1.0f; inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); //Calculate new rotation inRot.Rotation = LookAt(inPos.Position, targetPosition); //Change drone state to idle droneState = DroneStateTypes.Idle; entity.RemoveComponent(ComponentTypes.COMPONENT_RIGIDBODY); _timeSinceTrigger = 0.0f; inAudio.SetAudioBuffer("idle-woah", true); _targettingPlayer = false; _targettingNodePath = false; //Change vaporwave post process effects active variable to false ResourceManager.GetPostProccessEffects()["AttackShake"].Active = false; } }
private void IdleDroneLogic(ComponentTargetNode targetNode, ComponentPosition inPos, ComponentRotation inRot, ComponentVelocity inVel, ComponentSpeedModifier inSpeed, ComponentAudio inAudio, EnvironmentLocationScript inLoc, float inDelta) { Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; if (_player != null) { Vector3 playerPosition = (_player.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; EnvironmentLocationScript playerLocation = null; List <IComponent> scripts = _player.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is EnvironmentLocationScript) { playerLocation = script.script as EnvironmentLocationScript; continue; } } //Fastest way to calculate the distance float deltaX = playerPosition.X - inPos.Position.X; float deltaY = playerPosition.Y - inPos.Position.Y; float deltaZ = playerPosition.Z - inPos.Position.Z; double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); //If the distance between the player and drone is less than 5 then we change state if (distance < _viewRange && inLoc.EnvironmentLocation == playerLocation.EnvironmentLocation && CanDroneSeeTarget(inPos.Position, targetPosition, playerPosition)) { //Other logic (speed mod change) inSpeed.SpeedMod = 3.0f; //Change drone state to aggressive droneState = DroneStateTypes.Aggressive; entity.AddComponent(new ComponentRigidbody()); //Change sound to the trigger sound inAudio.SetAudioBuffer("trigger-woah", false); //Change vaporwave post process effects active variable to true ResourceManager.GetPostProccessEffects()["AttackShake"].Active = true; _targettingPlayer = true; } else if (targetPosition == inPos.Position) { //If we've reached our target, update to a new target FindNewTarget(targetNode, inPos, inVel, inRot); } //Update position Vector3 travelDistance = ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); //Fastest way to calculate the distance deltaX = targetPosition.X - inPos.Position.X; deltaY = targetPosition.Y - inPos.Position.Y; deltaZ = targetPosition.Z - inPos.Position.Z; double distanceToNode = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); if (travelDistance.Length > distanceToNode) { inPos.Position = targetPosition; } else { inPos.Position += travelDistance; } _previousPositions.Add(inPos.Position); if (_previousPositions.Count > 6) { _previousPositions.Remove(_previousPositions.First()); if (CheckIfStuck()) { //Since we can't see the player anymore, we'll find the nearest node in our environment to follow targetNode.TargetNode = FindNearestEnvironmentNode(inPos, inLoc, "CorridorNode"); targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; //Other logic (speed mod change, reset velocity to target node (temp)) inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); //Calculate new rotation inRot.Rotation = LookAt(inPos.Position, targetPosition); } } } else { _player = _sceneManager.Scenes["Main"].Entities.Find(delegate(Entity e) { return(e.Name == "Camera1"); }); } }
public void ItemCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, Entity item, ComponentAudio faudioComponent, ComponentTexture ftextureComponent) { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1 && ftextureComponent.Texture != 0) { faudioComponent.Start(); ftextureComponent.remove(); fpositionComponent.Position = offscreen; } }
private void Motion(ComponentPosition pos, ComponentVelocity vel) { pos.Position += vel.Velocity * MyGame.dt; }
public void Motion(ComponentPosition position, ComponentVelocity velocity) { position.Position = position.Position + (velocity.Velocity * GameScene.dt); }
public void Motion(ComponentPosition positionComponent, ComponentVelocity velocityComponent) { positionComponent.Position = positionComponent.Position + velocityComponent.Velocity * GameScene.dt; }
private void Motion(ComponentTransform transform, ComponentVelocity vel) { transform.position += vel.Velocity * Time.deltaTime; }
public override void OnAction() { List <IComponent> components = player.Components; IComponent positionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); Vector3 positionPlayer = ((ComponentPosition)positionComponent).Position; Location playerLocation = new Location(); playerLocation.mapXPosition = (int)Math.Abs((map.GetStartX() - 0.5f) - positionPlayer.X); playerLocation.mapYPosition = (int)Math.Abs((map.GetStartY() - 0.5f) - positionPlayer.Z); List <IntelligenceSetUp> setUps = new List <IntelligenceSetUp>(); foreach (Entity entity in entities) { components = entity.Components; positionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); IComponent directionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_DIRECTION); }); IComponent velocityComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_VELOCITY); }); ComponentVelocity velocity = (ComponentVelocity)velocityComponent; ComponentDirection direction = (ComponentDirection)directionComponent; direction.DirectionChange = 0; velocity.Velocity = 0; if (!hasMovement) { continue; } if (playerLocation.mapXPosition < 0 || playerLocation.mapXPosition > map.GetWidth() - 1 || playerLocation.mapYPosition < 0 || playerLocation.mapYPosition > map.GetWidth() - 1) { //Don't do anything the player is outside the map continue; } IComponent artificalComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_ARTIFICAL); }); ComponentArtificalInput componentArtifical = (ComponentArtificalInput)artificalComponent; Vector3 positionGhost = ((ComponentPosition)positionComponent).Position; Location ghostPosition = new Location(); ghostPosition.mapXPosition = (int)Math.Abs((map.GetStartX() - 0.5f) - positionGhost.X); ghostPosition.mapYPosition = (int)Math.Abs((map.GetStartY() - 0.5f) - positionGhost.Z); if (ghostPosition.mapXPosition < 0 || ghostPosition.mapXPosition > map.GetWidth() || ghostPosition.mapYPosition < 0 || ghostPosition.mapYPosition > map.GetWidth()) { //Don't do anything the player is outside the map map.KillGhost(entity); continue; } IntelligenceSetUp setUp = new IntelligenceSetUp(); setUp.velocity = velocity; setUp.direction = direction; setUp.ghostLocation = ghostPosition; setUp.algorithm = componentArtifical.GetAlgorithm(); setUp.preferredDirection = componentArtifical.GetPreferredDirection(); setUp.position = (ComponentPosition)positionComponent; setUp.fullSpeed = componentArtifical.FullSpeed(); setUps.Add(setUp); } for (int i = 0; i < setUps.Count; i++) { Vector2 ghostMapLocation = new Vector2(setUps[i].position.Position.X, setUps[i].position.Position.Z); Vector3 target = setUps[i].algorithm.BuildPath(ghostMapLocation, setUps[i].ghostLocation, map, playerLocation, setUps[i].preferredDirection); GoToTarget(setUps[i].direction, setUps[i].velocity, setUps[i].position, target, setUps[i].fullSpeed, positionPlayer); } }
public void Motion(ComponentPosition pPos, ComponentVelocity pVel, ComponentDirection pDir) { pPos.Position += pDir.Direction * (pVel.Velocity * GameScene.dt); }
public void Collision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent) { var still = Vector3.Zero; if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1) { if (velocityComponent.Velocity == up) { positionComponent.Position += downfix; velocityComponent.Velocity = still; } else if (velocityComponent.Velocity == down) { positionComponent.Position += upfix; velocityComponent.Velocity = still; } else if (velocityComponent.Velocity == right) { positionComponent.Position += leftfix; velocityComponent.Velocity = still; } else if (velocityComponent.Velocity == left) { positionComponent.Position += rightfix; velocityComponent.Velocity = still; } } }