public void Move(EvalContext context, RuneType.Direction direction, int distance) { if (distance <= 0 || distance > 4) { Debug.LogError("Can only move object with distance between 1 and 3"); return; } Entity target = context.Target; Moveable moveable = target.GetComponent <Moveable>(); if (moveable == null) { Debug.LogError($"Target is not moveable"); return; } //Rigidbody rb = target.GetComponent<Rigidbody>(); //RuneStock.Inst.DeductRune(new RuneType(direction)); Vector3 finalPos = target.transform.position; switch (direction) { case RuneType.Direction.Left: finalPos.x -= distance; moveable.XTendency = -distance; break; case RuneType.Direction.Right: finalPos.x += distance; moveable.XTendency = distance; break; case RuneType.Direction.Up: finalPos.y += distance; moveable.YTendency = distance; break; case RuneType.Direction.Down: finalPos.y -= distance; moveable.YTendency = -distance; break; } moveable.Ungravitate(); StartCoroutine ( StartGradualAction ( timer => { } , () => { target.transform.position = new Vector3(Mathf.Round(target.transform.position.x), Mathf.Round(target.transform.position.y), 0); moveable.XTendency = moveable.YTendency = 0; moveable.Gravitate(); } , 1.0f ) ); //StartCoroutine( // StartGradualAction(timer => // { // target.transform.position = Vector3.Lerp( // target.transform.position, finalPos, timer); // }, () => // { // target.transform.position = finalPos; // }, // 1.0f // ) //); }
protected override void SetPrefabRuneType(RuneType value) { Dir = value.direction; }
public void Move(EvalContext context, RuneType.Direction direction, int distance) { Debug.Log($"Moved to {direction.ToString()} by distance {distance}"); }