public override void HandleMovement(Character c) { if (c.Movement == new Vector3Int(0, 0, 0)) { ToState(c, new StateIdle()); } if (!Input.GetKey(KeyCode.LeftShift)) { ToState(c, new StateWalk()); } c.Animator.ChangeFacingDirection(c.CurrentFacing); _whereAmI = WorldGrid.GetGridPositionFromWorld(c.transform.position); DataTile dt = WorldGrid.GetCellAt(_whereAmI + c.Movement); if (!dt.walkable) { Debug.LogError("Sorry buddy, you cant move there!"); return; } _oldPos = c.transform.position; _nextPos = WorldGrid.GetWorldPositionFromGrid(_whereAmI + c.Movement); _difference = _nextPos - _oldPos; _timer = 0; }
void Start() { currentFacing = SpriteAnimDirectional.Facing.DW; _timer = movementTime; _whereAmI = WorldGrid.GetGridPositionFromWorld(transform.position); animator = new SpriteAnimDirectional(sp_walk_up, sp_walk_dw, sp_walk_lf, sp_walk_rg, movementTime / 2, GetComponent <SpriteRenderer>()); animator.ChangeFacingDirection(currentFacing); transform.position = WorldGrid.GetWorldPositionFromGrid(_whereAmI); }
public override void OnEnterState(Character c) { c.Animator.SetSprites( c.sp_idle_up, c.sp_idle_dw, c.sp_idle_rg, c.sp_idle_lf ); c.Animator.SetFrameTime(c.MovementTime); c.Animator.ChangeFacingDirection(c.CurrentFacing); _whereAmI = WorldGrid.GetGridPositionFromWorld(c.transform.position); c.transform.position = WorldGrid.GetWorldPositionFromGrid(_whereAmI); }
void handleGrid() { Vector3Int whereAmI_old = whereAmI; Vector3Int whereAmIFacing_old = whereAmIFacing; whereAmI = WorldGrid.GetGridPositionFromWorld(transform.position); handleNextGrid(); if (whereAmIFacing_old != whereAmIFacing) { WorldGrid.SetColorInGridPos(whereAmIFacing_old, Color.white); WorldGrid.SetColorInGridPos(whereAmIFacing, Color.blue); } if (whereAmI_old != whereAmI) { WorldGrid.SetColorInGridPos(whereAmI_old, Color.white); WorldGrid.SetColorInGridPos(whereAmI, Color.red); } }
void handleMovement(Vector3Int movement) { if (movement == new Vector3Int(0, 0, 0)) { return; } animator.ChangeFacingDirection(currentFacing); _whereAmI = WorldGrid.GetGridPositionFromWorld(transform.position); DataTile dt = WorldGrid.GetCellAt(_whereAmI + movement); if (!dt.walkable) { return; } _oldPos = transform.position; _nextPos = WorldGrid.GetWorldPositionFromGrid(_whereAmI + movement); _difference = _nextPos - _oldPos; _timer = 0; }