private void Move() { Vector2 movVector = InputManager.ControllerHorizontalVector(); // Dont allow the play to move towards in others objects direction when colliding if (movVector.ToDirection().Equals(Colliding)) { movVector = Vector2.zero; _player.stateMch.Directorvector = movVector; return; } if (movVector.Equals(Vector2.zero)) { _player.stateMch.Directorvector = Vector2.zero; if (_player.CellScreen.activeSelf == false) { _player.CurrentState = new PlayerIdleState(_player); } return; } _player.stateMch.Directorvector = movVector; _player.gameObject.transform.position = _player.gameObject.transform.position + (Vector3)movVector * Time.deltaTime * _player.speed; }
public float GetValue(Vector2 vector) { if (vector.sqrMagnitude < this.zeroThreshold * this.zeroThreshold) { return(this.zeroVectorValue); } return(this.GetValue(vector.ToDirection() * Mathf.Rad2Deg)); }
/// <summary> /// Sets the parameters for the effect to indicate strength and direction /// </summary> /// <param name="strength">The amount of blur (0 - 1)</param> /// <param name="direction">A direction of the effect</param> /// <param name="opacity">The opacity of the effect 0-1</param> public Color GetBlurInfo(float strength, Vector2 direction, float opacity) { if (strength > 1) { strength = 1; } return(new Color((float)Math.Abs(direction.ToDirection().X), (float)Math.Abs(direction.ToDirection().Y), strength * opacity, 0)); }
public void OnPointerEnter(PointerEventData eventData) { Vector2 localPos = this.transform.InverseTransformPoint(eventData.position); var dir = localPos.ToDirection(); //OnDraw.SafeInvoke(this.Row, this.Col, dir); Debug.Log(string.Format("Mouse Enter! {0}/{1}", this.Row, this.Col)); //this.Center.gameObject.SetActive(true); }
public void Move(Vector2 input, float initialSpeed, float time, float finalSpeed = 0) { if (!CanWalk) { MoveForce = Vector3.zero; //cant add force return; } ; var acceleration = (finalSpeed - initialSpeed) * time; MoveForce = input.ToDirection() * acceleration * _data.Mass; Controller.ProcessForce(MoveForce); }
public void MoveTo(float x, float y, float speed = 1f, bool setFacing = false) { var dir = new Vector2(x - Owner.X, y - Owner.Y); if (dir.Length() > 1f) { dir.Normalize(); dir = dir * speed; } if (setFacing) { Owner.Facing = dir.ToDirection(); } Do(dir.X, dir.Y); }
/// <summary> /// Executed every fixed update cycle. /// </summary> protected virtual void FixedUpdate() { if (BlitEngine.Instance.State == GameState.Running) { var move = movement.normalized; var dir = movement.ToDirection(); if (move != Vector2.zero && !externalMovement) { rigidBody.MovePosition(rigidBody.position + move * Time.fixedDeltaTime * speed); } TriggerAnimation(dir); } else { TriggerAnimation(Direction.None); } }
private void Update() { if (!IsWalking) { return; } // update direction Transform player = GameObject.Find("Player").transform; Direction = (player.position - transform.position).normalized; // update animator Vector2 direction = Direction.ToDirection().ToVector2(); GetComponent <Animator>().SetFloat("DirectionX", direction.x); GetComponent <Animator>().SetFloat("DirectionY", direction.y); // attack if close to player if (Vector2.Distance(player.position, transform.position) < AttackDistance) { _animator.Play("Charge"); } }
public float GetValue(float angle, Vector2 forward) { return(GetValue(angle - forward.ToDirection(angle))); }
/// <summary> /// Move the entity to the center of an adjactent tile based /// on the movement vector /// </summary> /// <param name="Movement">A vector describing which direction the entity wants to go</param> public bool MoveTo(Vector2 Movement) { if (float.IsNaN(Movement.X) || float.IsNaN(Movement.Y)) { Movement.X = 0; Movement.Y = 0; } if (this.isTileMovement) { try { var direction = Movement.ToDirection(); if (direction != Directions.Null) { ITile tile = this.Tile.AdjacentTiles[(int)direction]; return MoveTo(tile); } else { return false; } } catch { return false; } } else { Vector2 destination = this.Position + Movement; Point pos = new Point ( (int)destination.X, (int)destination.Y ); if (this.tile.Rectangle.Contains(pos)) { this.position = destination; this.destinationRectangle.Location = pos; return false; } else { ITile dTile = this.Tile .AdjacentTiles .Where(x => x.Rectangle.Contains(pos)) .SingleOrDefault(); bool result = false; if (dTile.IsNotNull()) result = MoveTo(dTile); return result; } } }
/// <summary> /// Move the entity to the center of an adjactent tile based /// on the movement vector /// </summary> /// <param name="Movement">A vector describing which direction the entity wants to go</param> protected void MoveTo(Vector2 Movement) { ILocation tile = this.Location.GetLocation(Movement.ToDirection()); if (tile == null) return; if (!tile.IsBlocked) { this.destinationRectangle.Location = tile.Rect.Location; this.rectangle.Location = tile.Rect.Location; } }