//############### //## METHODS ## //############### private void checkPlayerDistance() { float distance = Vector2.Distance(PlayerPosition.position, transform.position); if (distance < AggressionRange && distance > StoppingDistance) { moveTowardsPlayer(); } else { mMoveHandler.Move(new Vector2(0, 0)); } }
private void FixedUpdate() { if (path != null) { // Check if we've reached the end of the path and stop execution if we have if (currentWaypoint >= path.vectorPath.Count) { reachedEndOfPath = true; return; } else { reachedEndOfPath = false; } if (path.GetTotalLength() < aggroRange) { // Calculate the direction to the current waypoint and move in it Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - rb.position).normalized; controller.Move(direction); // Check if we're close enough to the waypoint to move onto the next one float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]); if (distance < nextWaypointDistance) { currentWaypoint++; } } } }
public ActionResult Move(string playerId, T move) { lock (_game) { return(_game.Move(playerId, move)); } }
public static void MoveAtRandom(IMoveable moveable) { if (moveable.Position != null) { Point pos = moveable.Position; moveable.Move(new Point(Utilities.RandomNumber(pos.X - 1, pos.X + 1), Utilities.RandomNumber(pos.Y - 1, pos.Y + 1))); } }
public static void MoveAwayFrom(IMoveable moveable, IMappable mapObject) { if (moveable.Position != null && mapObject.Position != null && OpenNeighbors(moveable).Any()) { moveable.Move(OpenNeighbors(moveable).FirstOrDefault(p => MovementCost(moveable.Position, p, mapObject.Position) == GetMaxCost(moveable, mapObject))); } }
public void MoveSelectItem(Vector newPos) { if (curSelect is null) { return; } curSelect.Move(newPos); }
protected virtual void Update() { float move = InputManager.GetHorizontal(); if (move != 0) { moveable.Move(Vector2.right * move); } }
// Update is called once per frame void Update() { // We need the movement set up first before reading in inputs and moving the cursor. if (movement != null) { inputMove.ReadInput(); movement.Move(inputMove.HorizontalInput, inputMove.VerticalInput); } }
public void Move(InputAction.CallbackContext context) { if (isStunned) { mMovementHandler.Move(Vector2.zero); return; } Vector2 newMovement = context.action.ReadValue <Vector2>(); if (newMovement == Vector2.zero) { // this makes no sense //mCachedDirection = mCurMovement; } mCurMovement = newMovement; mMovementHandler.Move(newMovement); }
public static void MoveTowards(IMoveable moveable, Point position) { if (moveable.Position != null && OpenNeighbors(moveable).Any()) { double minCost = OpenNeighbors(moveable).Min(p => MovementCost(moveable.Position, p, position)); moveable.Move(OpenNeighbors(moveable).FirstOrDefault(p => MovementCost(moveable.Position, p, position) == minCost)); } }
//############# //## INPUT ## //############# public void OnMove(InputAction.CallbackContext context) { if (mMovementBlocked) { return; } Vector2 moveVal = context.ReadValue <Vector2>(); mMovement.Move(moveVal); }
/// <summary> /// Evaluates the current position of the enemy to decide whether to /// attack or not. /// </summary> void EvaluatePlayerPosition() { if (!player.healthProperties.alive) { return; } if (ProgressionManager.Instance.gameOver) { return; } Vector2 difference = player.transform.position - transform.position; var playerScreenPos = Camera.main.WorldToScreenPoint( player.transform.position ); moveable.TurnToScreenPoint(playerScreenPos); if (weaponAttacker == null) { weaponAttacker = GetComponentInChildren <IWeaponAttacker>(); } try { if (weaponAttacker.InRange(difference.magnitude)) { combat.Attack(); } else { moveable.Move(difference); } } catch (System.NullReferenceException) { Debug.LogWarning("It did it again"); moveable.Move(difference); } }
/// <summary> /// Moves object based on Horizontal and Vertical input axes. /// </summary> void ProcessMovementInput() { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (h == 0 && v == 0) { return; } moveable.Move(new Vector2(h, v)); }
void Update() { if (!isMoveAllowed) { return; } direction = DirectionToTarget(); direction *= Time.deltaTime; moveable.Move(direction); }
public void MoveHero(IMoveable hero, TimeSpan dt, Vector2 movementVector) { Contract.Assert(hero != null, "hero!=null"); Contract.Assert(movementVector != null, "movementVector!=null"); var distance = dt.TotalSeconds * hero.MovementSpeed; var dx = distance * movementVector.X; var dy = distance * movementVector.Y; hero.Move(dx, dy); }
private void MoveSelectionObject() { for (int i = 0; i < listISelectables.Count; i++) { IMoveable moveObject = listISelectables[i].GetInterface <IMoveable>(); if (moveObject != null) { moveObject.Move(vectorList[i]); } } vectorList.Clear(); }
protected void TryToMove() { if (isMoveAllowed) { if (IsCame) { EndMove(); return; } //transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * speed); //step equal 1 * deltaTime Vector3 newPosition = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime); Vector3 direction = newPosition - transform.position; moveable.Move(direction); } }
public static void MoveOnInput(IMoveable movable, Keys?[] keys, Vector2 speed) { //Check if the array contains 4 keys if (keys.Length != 4) { throw new ArgumentException("The length of the key array must be 4", "keys"); } //The amount to move the object Vector2 moveAmount = Vector2.Zero; for (int i = 0; i < 4; i++) { //Check if the keys is not null and is pressed if (keys[i].HasValue && KeyDown(keys[i].Value)) { switch (i) { //Up, down, right, left case 0: moveAmount.Y -= speed.Y; break; case 1: moveAmount.Y += speed.Y; break; case 2: moveAmount.X += speed.X; break; case 3: moveAmount.X -= speed.X; break; } } } //Move the object moveAmount *= TimeF.DeltaTime; movable.Move(moveAmount); }
static void Main() { List <Animal> animals = new List <Animal> { new Person("Person", 20), new Dog(5, 20) }; foreach (Animal animal in animals) { animal.Talk(); animal.TakeBreath(); } List <IJumpable> jumpables = new List <IJumpable> { new Person("Person", 20), new Dog(5, 20) }; foreach (IJumpable jumpable in jumpables) { jumpable.Jump(10); } List <IMoveable> moveables = new List <IMoveable> { new Person("Person", 20), new Dog(5, 20) }; foreach (IMoveable moveable in moveables) { moveable.Move(); } Person person = new Person("Person", 30); ISwimable swimable = person; swimable.Move(); IMoveable moveable1 = person; moveable1.Move(); }
public State Move(State state, char direction) { switch (direction) { case 'u': return(_moveUp.Move(state, direction: direction)); case 'd': return(_moveDown.Move(state, direction: direction)); case 'l': return(_moveLeft.Move(state, direction: direction)); case 'r': return(_moveRight.Move(state, direction: direction)); default: return(null); } }
private void Update() { if (_moveController == null) { Debug.LogError("[WASD Input] IMoveable interface must be implemented"); return; } if (_rotateController == null) { Debug.LogError("[WASD Input] IRotateable interface must be implemented"); return; } var direction = new Vector3(0, 0, Input.GetAxis("Vertical")); _moveController.Move(direction); var rotation = new Vector3(0, Input.GetAxis("Horizontal"), 0); _rotateController.Rotate(rotation); }
public void MoveFromAtoB(IMoveable moveable) { moveable.Move(); // System.Console.WriteLine($"Ride on {vehicle.NameVehicle}"); }
private void Move(IMoveable entity) { entity.Move(); }
// Update is called once per frame void Update() { moveable.Move(t); }
public void Run() { _rover.Move(); }
private void FixedUpdate() { _moveBehavior.Move(); }
public bool MoveObject(Vector2 relativeFrom, Vector2 relativeDelta, CameraBase camera, bool tryToClone, [CanBeNull] out IMoveable cloned) { if (_keepHighlight) { tryToClone = false; } else { _keepHighlight = true; } if (_justCloned) { tryToClone = false; } cloned = null; if (_arrowHighlighted != default(Vector3)) { var plane = new Plane(ParentMatrix.GetTranslationVector(), -camera.Look); var rayFrom = camera.GetPickingRay(relativeFrom, new Vector2(1f, 1f)); var rayTo = camera.GetPickingRay(relativeFrom + relativeDelta, new Vector2(1f, 1f)); if (!Ray.Intersects(rayFrom, plane, out var distanceFrom) || !Ray.Intersects(rayTo, plane, out var distanceTo)) { return(false); } var pointDelta = rayTo.Direction * distanceTo - rayFrom.Direction * distanceFrom; if (tryToClone) { cloned = _parent.Clone(); _justCloned = true; } var totalDistance = pointDelta.Length(); var resultMovement = new Vector3( pointDelta.X * _arrowHighlighted.X, pointDelta.Y * _arrowHighlighted.Y, pointDelta.Z * _arrowHighlighted.Z); resultMovement.Normalize(); resultMovement *= totalDistance; _parent.Move(resultMovement); UpdateBoundingBox(); return(true); } if (_circleHighlighted != default(Vector3)) { var rotationAxis = _circleHighlighted.X * _circleHighlighted.Y * _circleHighlighted.Z != 0f ? camera.Look : _circleHighlighted; if (tryToClone) { cloned = _parent.Clone(); _justCloned = true; } _parent.Rotate(Quaternion.RotationAxis(rotationAxis, relativeDelta.X * 10f)); UpdateBoundingBox(); return(true); } if (_scaleHighlighted) { var v = relativeDelta.X + relativeDelta.Y; _parent.Scale(new Vector3(v > 0f ? 1.01f : 1f / 1.01f)); UpdateBoundingBox(); return(true); } return(false); }
public static void MoveObject(IMoveable obj) { obj.Move(); }
public void Move(Transform t) { moveable_impl.Move(t); }
public void DoAction() { _move.Move(); }