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)); }
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; } }
void TriggerCollision() { if (FireCollisionEventOn == FireCollisionEventOn.FirstImpact && IsFirst || FireCollisionEventOn == FireCollisionEventOn.LastImpact && IsLast || FireCollisionEventOn == FireCollisionEventOn.EachImpact) { TargetReached?.Invoke(this, EventArgs.Empty); } }
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); }
/// <summary> /// Invokes the TargetReached event. /// </summary> protected void OnTargetReached() { TargetReached?.Invoke(); }
protected virtual void OnTargetReached() { TargetReached?.Invoke(); OnMoveEnded(); isWalkSoundPlayed = false; }
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); } } } }
public void FireThing() { TargetReached?.Invoke(); }