// Corrutina de movimiento con DoTween IEnumerator Move() { if (InteractableTouched()) { Debug.Log("Interactable touched!"); rb.DOMoveX(touchPosition.x - moveOffset, moveDuration); interactables[currentTouched].ShowDialog(); currentTouched = -1; // Vuelve a ponerlo por defecto } else { rb.DOMoveX(touchPosition.x, moveDuration); } yield return(null); }
public override Tween GetTween(UniTween.UniTweenTarget uniTweenTarget) { Rigidbody2D rb = (Rigidbody2D)GetComponent(uniTweenTarget); switch (command) { case Rigidbody2DCommand.Move: return(rb.DOMove(vector2, duration, snapping)); case Rigidbody2DCommand.MoveX: return(rb.DOMoveX(to, duration, snapping)); case Rigidbody2DCommand.MoveY: return(rb.DOMoveY(to, duration, snapping)); case Rigidbody2DCommand.Jump: return(rb.DOJump(vector2, jumpPower, numJumps, duration, snapping)); case Rigidbody2DCommand.Rotate: return(rb.DORotate(to, duration)); default: return(null); } }
public void MoveToPosition(float finalPositionOnX, bool spawnPlatform) { if (spawnPlatform) { PlatformManager.Instance.EnableNextPlatform(); } _PlayerRigidbody.DOMoveX(finalPositionOnX, _WalkDuration).SetEase(Ease.InOutExpo).OnComplete(() => ChoosePhase(spawnPlatform)); }
IEnumerator Start() { yield return(new WaitForSeconds(1f)); Sequence s = DOTween.Sequence(); s.Append(enemyBody.DOMoveX(moveDistance, 3f).SetRelative()); // s.Append(enemyBody.transform.DOScaleX(-1f, 0f)); s.AppendCallback(() => { FlipCharacter(); }); s.Append(enemyBody.DOMoveX(-moveDistance, 3f).SetRelative()); // s.Append(enemyBody.transform.DOScaleX(1f, 0f)); s.AppendCallback(() => { FlipCharacter(); }); s.SetLoops(-1, LoopType.Restart); }
public void OnThrown(bool toRight, Action onCatched) { this.onCatched = onCatched; moveSeq = DOTween.Sequence(); moveSeq.Append( rigidbody2D.DOMoveX(toRight ? moveDistance : -moveDistance, moveSeconds / 2) .SetRelative() .SetEase(Ease.OutSine) ); moveSeq.Append( rigidbody2D.DOMoveX(toRight ? -moveDistance : moveDistance, moveSeconds / 2) .SetRelative() .SetEase(Ease.InSine) ); moveSeq.onComplete += () => { onCatched.Invoke(); Destroy(gameObject); }; }
IEnumerator Move() { while (true) { yield return(new WaitForSeconds(Random.Range(stepTime.x, stepTime.y))); if (canMove) { float distance = Random.Range(stepDistance.x, stepDistance.y); body2d.DOMoveX(body2d.position.x + distance, distance).SetEase(Ease.InOutQuad).WaitForCompletion(); } } }
/// <summary> /// Moves the Rigidbody to the target on the Y axis only, at the given speed /// </summary> /// <param name="rigidbody">Body to move</param> /// <param name="target">Target to reach</param> /// <param name="speed">Speed at which to travel</param> /// <param name="offset">Distance offset on the Y axis to the target to reach</param> /// <returns>The tweener generated for this movement</returns> public static Tween DOMoveToY(this Rigidbody2D rigidbody, Transform target, float speed, float offset = 0f) { //Get Y target float y = target.position.x; if (offset > 0f) { //Flip if needed y += offset * (rigidbody.position.y > y ? 1f : -1f); } return(rigidbody.DOMoveX(y, Mathf.Abs(rigidbody.position.y - y) / speed) .SetUpdate(UpdateType.Fixed)); }
/// <summary> /// Moves the Rigidbody to the target on the X axis only, at the given speed /// </summary> /// <param name="rigidbody">Body to move</param> /// <param name="target">Target to reach</param> /// <param name="speed">Speed at which to travel</param> /// <param name="offset">Distance offset on the x axis to the target to reach</param> /// <returns>The tweener generated for this movement</returns> public static Tween DOMoveToX(this Rigidbody2D rigidbody, Transform target, float speed, float offset = 0f) { //Get X target float x = target.position.x; if (offset > 0f) { //Flip if needed x += offset * (rigidbody.position.x > x ? 1f : -1f); } return(rigidbody.DOMoveX(x, Mathf.Abs(rigidbody.position.x - x) / speed) .SetUpdate(UpdateType.Fixed)); }
IEnumerator Move() { float currentDistance = 0; do { yield return(new WaitForSeconds(Random.Range(stepTime.x, stepTime.y))); float distance = Random.Range(stepDistance.x, stepDistance.y); body2d.DOMoveX(body2d.position.x + distance, distance).SetEase(Ease.InOutQuad).WaitForCompletion(); currentDistance += distance; }while (currentDistance < totalDistance); }
public void Push(int direction, float length, float duration, AnimationCurve pushCurve = null) { AnimationCurve curve = pushCurve ?? AnimationCurve.Linear(0f, 0f, 1f, 1f); if (_pushTween != null && _pushTween.IsPlaying()) { _pushTween.Kill(false); } var end = _rb.position.x + (direction * length); _pushTween = _rb.DOMoveX(end, duration) .SetEase(curve) .OnStart(() => { _rb.velocity = Vector2.zero; }); }
/// <summary> /// Creates and returns a Tween for the informed component. /// The Tween is configured based on the attribute values of this TweenData file. /// </summary> /// <param name="transform"></param> /// <returns></returns> public Tween GetTween(Rigidbody2D rb) { switch (command) { case Rigidbody2DCommand.Move: return(rb.DOMove(vector2, duration, snapping)); case Rigidbody2DCommand.MoveX: return(rb.DOMoveX(to, duration, snapping)); case Rigidbody2DCommand.MoveY: return(rb.DOMoveY(to, duration, snapping)); case Rigidbody2DCommand.Jump: return(rb.DOJump(vector2, jumpPower, numJumps, duration, snapping)); case Rigidbody2DCommand.Rotate: return(rb.DORotate(to, duration)); default: return(null); } }
private void DrunkMove() { m_Rigidbody.DOMoveX(transform.position.x + DrunkX, 0.66f).SetEase(Ease.InBounce).OnComplete(() => { m_Rigidbody.DOMoveX(transform.position.x + DrunkXm, 0.33f).SetEase(Ease.OutBounce).onComplete(); }); //m_Rigidbody.DOMoveX(-0.5f, 1).SetEase(Ease.InCirc); }
public override void OnEnter() { var _target = Fsm.GetOwnerDefaultTarget(gameObject); if (_target != null) { Vector2 Vector2setup = to.IsNone ? new Vector2(x.Value, y.Value) : to.Value; if (!x.IsNone) { Vector2setup.x = x.Value; } if (!y.IsNone) { Vector2setup.y = y.Value; } to.Value = Vector2setup; } rigidBody = _target.GetComponent <Rigidbody2D>(); if (rigidBody == null) { Debug.LogWarning("<b>[DotweenJumpRigidbody2dTo]</b><color=#FF9900ff>Missing Rigidbody component</color>", this.Owner); return; } setFinal = new TweenParams().SetDelay(setDelay.Value).SetAutoKill(setAutoKill.Value).SetSpeedBased(isSpeedBased.Value).SetRelative(setRelative.Value).OnComplete(MyCallback); switch (loopTypeSelect) { case loopType.None: if (settingLoops > 0 || settingLoops < 0) { Debug.LogWarning("<b>[DotweenCamera]</b><color=#FF9900ff>!!! Loop Time is set but no 'Loop Type' is selected !!! </color>", this.Owner); } break; case loopType.Yoyo: setFinal.SetLoops(settingLoops, LoopType.Yoyo); break; case loopType.Restart: setFinal.SetLoops(settingLoops, LoopType.Restart); break; case loopType.Incremental: setFinal.SetLoops(settingLoops, LoopType.Incremental); break; } if (!tag.IsNone) { setFinal.SetId(tag.Value); } bool _isNullOrEmpty = orInputID.IsNone || orInputID == null || string.IsNullOrEmpty(orInputID.Value); if (_isNullOrEmpty == false) { setFinal.SetId(orInputID.Value); } bool obj_isNullOrEmpty = gameObjectId.IsNone || gameObjectId.Value == false; if (obj_isNullOrEmpty == false) { setFinal.SetId(Fsm.GetOwnerDefaultTarget(gameObject)); } switch (easeTypeSelect) { case setEaseType.none: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.Linear); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.Linear)); } break; case setEaseType.InSine: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InSine); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InSine)); } break; case setEaseType.OutSine: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutSine); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutSine)); } break; case setEaseType.InOutSine: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutSine); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutSine)); } break; case setEaseType.InQuad: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InQuad); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InQuad)); } break; case setEaseType.OutQuad: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutQuad); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutQuad)); } break; case setEaseType.InOutQuad: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutQuad); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutQuad)); } break; case setEaseType.InCubic: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InCubic); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InCubic)); } break; case setEaseType.OutCubic: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutCubic); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutCubic)); } break; case setEaseType.InOutCubic: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutCubic); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutCubic)); } break; case setEaseType.InQuart: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InQuart); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InQuart)); } break; case setEaseType.OutQuart: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutQuart); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutQuart)); } break; case setEaseType.InOutQuart: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutQuart); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutQuart)); } break; case setEaseType.InQuint: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InQuint); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InQuint)); } break; case setEaseType.OutQuint: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutQuint); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutQuint)); } break; case setEaseType.InOutQuint: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutQuint); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutQuint)); } break; case setEaseType.InExpo: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InExpo); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InExpo)); } break; case setEaseType.OutExpo: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutExpo); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutExpo)); } break; case setEaseType.InOutExpo: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutExpo); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutExpo)); } break; case setEaseType.InCirc: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InCirc); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InCirc)); } break; case setEaseType.OutCirc: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutCirc); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutCirc)); } break; case setEaseType.InOutCirc: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutCirc); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutCirc)); } break; case setEaseType.InElastic: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InElastic); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InElastic)); } break; case setEaseType.OutElastic: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutElastic); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutElastic)); } break; case setEaseType.InOutElastic: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutElastic); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutElastic)); } break; case setEaseType.InBack: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InBack); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InBack)); } break; case setEaseType.OutBack: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutBack); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutBack)); } break; case setEaseType.InOutBack: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutBack); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutBack)); } break; case setEaseType.InBounce: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InBounce); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InBounce)); } break; case setEaseType.OutBounce: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutBounce); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutBounce)); } break; case setEaseType.InOutBounce: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutBounce); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutBounce)); } break; case setEaseType.Flash: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.Flash); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.Flash)); } break; case setEaseType.InFlash: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InFlash); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InFlash)); } break; case setEaseType.OutFlash: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.OutFlash); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.OutFlash)); } break; case setEaseType.InOutFlash: if (enableEaseFactory.Value == false) { setFinal.SetEase(Ease.InOutFlash); } if (enableEaseFactory.Value == true) { setFinal.SetEase(EaseFactory.StopMotion(easeFactoryFps.Value, Ease.InOutFlash)); } break; case setEaseType.AnimationCurve: setFinal.SetEase(animationCurve.curve); break; } // Update + TimeScale switch (updateTypeSelect) { case updateType.Normal: setFinal.SetUpdate(UpdateType.Normal, isTimeIndependent.Value); break; case updateType.Fixed: setFinal.SetUpdate(UpdateType.Fixed, isTimeIndependent.Value); break; case updateType.Late: setFinal.SetUpdate(UpdateType.Late, isTimeIndependent.Value); break; } // Easy part to edit for other DotTween actions ---> switch (dotweenTypeSelect) { case doTweenType.DoMove: rigidBody.DOMove(to.Value, duration.Value, snapping.Value).SetAs(setFinal); break; case doTweenType.DoMoveX: float x = to.Value.x; rigidBody.DOMoveX(x, duration.Value, snapping.Value).SetAs(setFinal); break; case doTweenType.DoMoveY: float y = to.Value.y; rigidBody.DOMoveY(y, duration.Value, snapping.Value).SetAs(setFinal); break; } // <--- if (startEvent != null) { Fsm.Event(startEvent); Finish(); } }
public static Tweener DOMoveX(this Rigidbody2D target, Position1DTweenConfig c) { return(target.DOMoveX(c.To, c.Duration, c.Snapping)); }