protected override void InnerUpdate(GameTime time) { if (path != null && move) { if ((NextTile.Position - Center).LengthSquared() < WalkAccuracy()) { if (path.IsDone) { CurrentTile = NextTile; path = null; move = false; TargetReached?.Invoke(NextTile); return; } CurrentTile = NextTile; path.Reached(NextTile); NextTile = path.Next(); if (map.IsInteractive(NextTile)) { map.GetInteractiveTiles(NextTile)[0].Interact(this); move = false; } } Vector2 dir = (NextTile.Position - Center); dir.Normalize(); Accelerate(Speed * dir); } else if (path != null && !move) { move = map.GetInteractiveTiles(NextTile)[0].InteractionDone; } }
public override void Update(GameTime gameTime) { // Check if the projectile has reached the ground. if (position.Z < 0) { var enemies = enemyManager.GetEnemiesInRange(new Vector2(position.X, position.Y), 1.5f); foreach (var enemy in enemies) { enemy.Attack(20); } stopwatch.Stop(); TargetReached?.Invoke(this); } // Calculate the current position from the elapsed time. var time = (float)stopwatch.Elapsed.TotalSeconds; displacement = (initialVelocity * time) + (0.5f * (Acceleration * (float)Math.Pow(time, 2))); position = initialPosition + displacement; // Update the actual position on the screen. sprite.Position = map.MapToScreen(new Vector2(position.X, position.Y)) + new Vector2(0, -position.Z * (map.TiledMap.TileHeight / 2)); }
void TriggerCollision() { if (FireCollisionEventOn == FireCollisionEventOn.FirstImpact && IsFirst || FireCollisionEventOn == FireCollisionEventOn.LastImpact && IsLast || FireCollisionEventOn == FireCollisionEventOn.EachImpact) { TargetReached?.Invoke(this, EventArgs.Empty); } }
//----------------------------------------------------------------------------- public void Execute(int index) { var velocity = Velocities[index].Value; var position = Positions[index].Value; var goal = Goals[index]; var currentGoal = goal.Current; if (TargetReached[index].CurrentGoal != currentGoal && currentGoal != TileSystem.k_InvalidHandle) { TargetReached[index] = new TargetReached { Value = 0, CurrentGoal = currentGoal } } ; var targetFlowFieldContribution = new float3(0, 0, 0); var terrainFlowFieldContribution = new float3(0, 0, 0); // This is what we want to do, but the targetFlowField is marked as [WriteOnly], // which feels like a bug in the JobSystem var gridIndex = GridUtilties.WorldToIndex(Settings, position); if (gridIndex != -1) { terrainFlowFieldContribution = FlowField(velocity, TerrainFlowfield[gridIndex], SteerParams.TerrainFieldWeight); if (currentGoal != TileSystem.k_InvalidHandle && FlowFields.Length > 0 && TargetReached[index].Value == 0) { var flowFieldValue = FlowFields[FlowFieldLength * currentGoal + gridIndex]; if (IsCloseToTarget(goal, position)) { TargetReached[index] = new TargetReached { Value = 1, CurrentGoal = currentGoal } } ; else { targetFlowFieldContribution = FlowField(velocity, flowFieldValue, SteerParams.TargetFieldWeight); } } } var normalizedForces = math_experimental.normalizeSafe ( Alignment(index, velocity) + Cohesion(index, position) + Separation(index) + terrainFlowFieldContribution + targetFlowFieldContribution ); var newVelocity = Velocity(velocity, normalizedForces); Velocities[index] = new Velocity { Value = newVelocity }; }
public void Execute(int index) { OutputPositions[index] = new Position { Value = Positions[index].Value }; OutputRotations[index] = new Rotation { Value = Rotations[index].Value }; OutputVelocities[index] = new Velocity { Value = Velocities[index].Value }; OutputTargetReached[index] = new TargetReached { Value = TargetReached[index].Value, CurrentGoal = TargetReached[index].CurrentGoal }; }
public void Awake() { model = gameObject.GetComponent <SpriteRenderer>(); if (model) { startColor = model.color; } lerp = GetComponent <TargetReached>(); aIDestinationSetter = GetComponent <AIDestinationSetter>(); speed = baseSpeed; lerp.OnDestinationReached.AddListener(delegate { DestinationReached(); }); }
public void Parse(NewTickPacket packet) { foreach (Status status in packet.Statuses) { var thing = Players.FirstOrDefault(x => x.PlayerData.OwnerObjectId == status.ObjectId); if (thing != null) { thing.Parse(status); } Entity entity = Client.GetEntity(status.ObjectId); if (entity == null) { continue; } if (!EntityPaths.ContainsKey(entity)) { EntityPaths[entity] = new List <Location>(); } EntityPaths[entity].Add(status.Position); if (TargetEntityPathCopyThing != null && TargetEntity?.Status.ObjectId == entity.Status.ObjectId) { TargetEntityPathCopyThing.Add(status.Position); } } if (TargetEntityPathCopyThing?.Count() > 0) { TargetLocation = TargetEntityPathCopyThing.First(); } if (TargetLocation != null) { Location result = Lerp(Client.PlayerData.Pos, TargetLocation, Client.PlayerData.TilesPerTick()); Client.SendGoto(result); if (result.ToString() == TargetLocation.ToString()) { TargetLocation = null; if (TargetEntityPathCopyThing?.Count() > 0) { OnTargetReached(); } else { TargetReached?.Invoke(); } } } }
private void Update() { if (Time.time - _targetReachedTime < StayStillTime) { return; } // Normalized so distance doesn't affect movement speed. var targetDirection = ((Vector3)TargetPosition - transform.position).normalized; transform.position += targetDirection * MovementSpeed * Time.deltaTime; if (Vector2.Distance(transform.position, TargetPosition) < _targetReachedTolerance) { _targetReachedTime = Time.time; TargetReached?.Invoke(this, EventArgs.Empty); } }
private void CheckIfReachedTarget() { if (!_navMeshAgent.pathPending) { if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance) { if (!_navMeshAgent.hasPath || _navMeshAgent.velocity.sqrMagnitude == 0f) { if (_invokedTargetReachedEvent) { _currentMovementState = EnemyMovementState.FollowingTarget; } else { _currentMovementState = EnemyMovementState.Idling; _invokedTargetReachedEvent = true; } TargetReached?.Invoke(this, EventArgs.Empty); } } } }
private void Update() { DrawPath(); if (path.Count > 0) { self.position = Vector2.MoveTowards(self.position, target, speed * Time.deltaTime); self.position = new Vector3(self.position.x, self.position.y, self.position.y * 10f); if ((Vector2)self.position == target) { path.RemoveAt(0); if (path.Count == 0) { Stop(); TargetReached?.Invoke(); } else { target = pathfinding.Grid.GetWorldPos(path[0].x, path[0].y, cage.transform.position) + Vector2.up * (Random.value > 0.5? Random.Range(0.02f, 0.04f): -Random.Range(0.02f, 0.04f)); anim.Walk(target - (Vector2)self.position); } } } }
protected virtual void DispatchTargetReached() { TargetReached?.Invoke(this, EventArgs.Empty); }
public void Activity() { values2DInput.X = 0; values2DInput.Y = 0; if (Target != null && Owner?.CurrentMovement != null && IsActive) { var targetX = Target.Value.X; var targetY = Target.Value.Y; var xDiff = targetX - Owner.Position.X; var yDiff = targetY - Owner.Position.Y; const float epsilon = 1; if (Math.Abs(xDiff) < epsilon && Math.Abs(yDiff) < epsilon && RemoveTargetOnReaching) { TargetReached?.Invoke(Owner); if (Path.Count > 0) { Target = Path[0]; Path.RemoveAt(0); } else { Target = null; } } else if (xDiff != 0 || yDiff != 0) { bool shouldMoveFullSpeed; if (StopOnTarget) { var currentMovementLength = Owner.Velocity.Length(); var currentRatioOfMax = currentMovementLength / Owner.CurrentMovement.MaxSpeed; var currentTimeToSlowDown = currentRatioOfMax * Owner.CurrentMovement.DecelerationTime; var maxSpeed = Owner.CurrentMovement.MaxSpeed; var maxAccelerationValue = -maxSpeed / Owner.CurrentMovement.DecelerationTime; //// create the temporary vectors: // Not sure where but there's an off-by-1 error somewhere, so account for it by subtracting one frame. var position = new Vector3((float)(2 * currentMovementLength * +FlatRedBallServices.Game.TargetElapsedTime.TotalSeconds), 0, 0); var velocity = new Vector3(currentMovementLength, 0, 0); var acceleration = new Vector3(maxAccelerationValue, 0, 0); var positionAfterTime = FlatRedBall.Math.MathFunctions.GetPositionAfterTime( ref position, ref velocity, ref acceleration, currentTimeToSlowDown); var lengthToSlow = Math.Abs(positionAfterTime.X); shouldMoveFullSpeed = (xDiff * xDiff) + (yDiff * yDiff) > lengthToSlow * lengthToSlow; } else { shouldMoveFullSpeed = true; } if (shouldMoveFullSpeed) { var angle = (float)System.Math.Atan2(yDiff, xDiff); values2DInput.X = (float)Math.Cos(angle); values2DInput.Y = (float)Math.Sin(angle); } } } }
// Start is called before the first frame update void Start() { Init(); TargetReached.AddListener(TargetCity); }
public void VariableRuleCountTest() { /* Rule: IntBetween(x,y) * * {1,10} * / \ * {1,5} {6,10} * / \ / \ * {1,3} {4,5} {6,8} {9,10} * / | \ / \ / | \ / \ * {1}{2}{3}{4}{5}{6}{7}{8}{9}{10} */ Log.logLevel = Log.LogLevels.NONE; RuleMSX rmsx = new RuleMSX(); RuleSet ruleSet = rmsx.createRuleSet("VariableRuleSet"); // Set min and max of target range int numMin = 1; int numMax = 10000; // Set value for target int target = 9999; TargetReached targetReached = new TargetReached(); RuleAction reached = rmsx.createAction("reached", targetReached); Accumulator count = new Accumulator(0); // Setup rule tree createNRules(rmsx, ruleSet, reached, count, numMin, numMax); DataSet dataSet = rmsx.createDataSet("TargetTestDataSet"); // Set datapoint for target dataSet.addDataPoint("target", new GenericIntDataPointSource(target)); // Set datapoint for result dataSet.addDataPoint("result", new GenericIntDataPointSource(0)); //System.Console.WriteLine("Report: \n\n" + ruleSet.report()); ruleSet.Execute(dataSet); int maxMS = 40000; int step = 10; while (maxMS > 0) { if (targetReached.fired) { break; } System.Threading.Thread.Sleep(step); maxMS -= step; } if (maxMS == 0) { System.Console.WriteLine("Timeout"); } ruleSet.Stop(); System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime()); System.Console.WriteLine("Number of Evaluations: " + count.value().ToString()); int result = (int)((GenericIntDataPointSource)dataSet.getDataPoint("result").GetSource()).GetValue(); Assert.True(target == result); }
/// <summary> /// Invokes the TargetReached event. /// </summary> protected void OnTargetReached() { TargetReached?.Invoke(); }
public void FireThing() { TargetReached?.Invoke(); }
protected virtual void OnTargetReached() { TargetReached?.Invoke(); OnMoveEnded(); isWalkSoundPlayed = false; }