private void InitSequences() { var worldMap = SpaceUtil.WorldMap; float startYPosition = worldMap.Top.y + SpriteMap.HeightHalf; float targetYPosition = (worldMap.Center.y + (worldMap.Top.y * 2f)) * 0.333f; float yDiff = targetYPosition - startYPosition; Vector3 moveDistance = new Vector3(0, yDiff, 0); float rotateTimeHalf = RotateTime * 0.5f; // Initial sequence var moveDown = new MoveBy(this, moveDistance, InitialTravelTime); var setVelocity = new GameTaskFunc(this, () => Velocity = new Vector2(0, -FinalTravelSpeed)); var initialRotateLeft = new RotateTo(this, AngleDown, MinAngle, rotateTimeHalf); var initialSequence = new Sequence(moveDown, setVelocity, initialRotateLeft); // Infinite sequence var fireLeft = new GameTaskFunc(this, FireLeft); var rotateMiddle1 = new RotateTo(this, MinAngle, AngleDown, rotateTimeHalf); var fireDown = new GameTaskFunc(this, FireDown); var rotateRight = new RotateTo(this, AngleDown, MaxAngle, rotateTimeHalf); var fireRight = new GameTaskFunc(this, FireRight); var rotateMiddle2 = new RotateTo(this, MaxAngle, AngleDown, rotateTimeHalf); var rotateLeft = new RotateTo(this, AngleDown, MinAngle, rotateTimeHalf); var infiniteSequence = new Sequence(fireLeft, rotateMiddle1, fireDown, rotateRight, fireRight, rotateMiddle2, fireDown, rotateLeft); var repeat = new RepeatForever(infiniteSequence); Behavior = new EndlessSequence(repeat, initialSequence); }
// Updates RotateTo anim type // Returns true if anim is over private static bool UpdateRotateAnim(RotateTo rotateAnim) { bool bAnimComplete = false; Quaternion targetRotation = Quaternion.Euler(rotateAnim.path[rotateAnim.curTargetIndex]); rotateAnim.targetObj.transform.rotation = Quaternion.RotateTowards(rotateAnim.targetObj.transform.rotation, targetRotation, rotateAnim.animSpeed * Time.deltaTime); //if(anim.path[anim.curTargetIndex] == anim.targetObj.transform.eulerAngles) // Debug.Log("targetRotation.eulerAngles "+targetRotation.eulerAngles.x + "y "+targetRotation.eulerAngles.y +"z "+targetRotation.eulerAngles.z); // Debug.Log("rotateAnim.targetObj.transform.eulerAngles "+rotateAnim.targetObj.transform.eulerAngles.x + "y "+rotateAnim.targetObj.transform.eulerAngles.y +"z "+rotateAnim.targetObj.transform.eulerAngles.z); if (targetRotation.eulerAngles.normalized == rotateAnim.targetObj.transform.eulerAngles.normalized) { if (rotateAnim.curTargetIndex < rotateAnim.path.Length - 1) { // Step to the next animation key point rotateAnim.curTargetIndex++; } else { if (rotateAnim.curLoopIndex == rotateAnim.loopCount) { bAnimComplete = true; } else { rotateAnim.curLoopIndex++; rotateAnim.curTargetIndex = 1; } } } return(bAnimComplete); }
// Update is called once per frame void Update() { if (hold) { if (Input.GetMouseButtonUp(0)) { hold = false; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 500, 1 << SpinHitPadLayer)) { var v = ToVector2(Multi((hit.point - Center), DirVector)); var angle = Mathf.Atan2(v.x, v.y) - holdAngle; angle = (angle / (2 * Mathf.PI)) * 360; var rotation = RotateVector * angle; rotation = rotation + new Vector3(360, 360, 360); rotation += startRotation; var minDR = float.MaxValue; var idx = 0; for (var i = 0; i < AlignRotation.Length; i++) { var align = AlignRotation[i]; if (DR(align, rotation) < minDR) { minDR = DR(align, rotation); idx = i; } } var option = new RotateTo.RotateOptions(RotateObject, AlignRotation[idx], AlignTime); option.OnFinished += (sender, e) => { var callback = RotateObject.GetComponent <WaypointCallback>(); if (callback != null) { callback.ConnectCallback(idx); } }; RotateTo.Start(option); } SpinHitPad.gameObject.SetActive(false); } else { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 500, 1 << SpinHitPadLayer)) { var v = ToVector2(Multi((hit.point - Center), DirVector)); var angle = Mathf.Atan2(v.x, v.y) - holdAngle; angle = (angle / (2 * Mathf.PI)) * 360; var rotation = RotateVector * angle; rotation += startRotation; RotateObject.transform.Rotate(rotation - RotateObject.transform.rotation.eulerAngles); } } } }
public void StartRotating(RotateTo target) { rotate = target; rotate.start(); Debug.Log("Rotate Started!"); character = target.agent.GetComponent <ThirdPersonCharacter>(); rotating = true; }
public void RotateFurniture(Furniture_Recepteur recepteur, Vector3 oldRotation, Vector3 newRotation) { Commande commande = new RotateTo(recepteur.getGameObject(), oldRotation, newRotation); commande.Do(); commandeList.Push(commande); editManager.RefreshInfos(); }
public static RotateTo Create(float duration, Vector3 dstAngle) { RotateTo rotateto = new RotateTo(); if (rotateto.InitWithDuration(duration, dstAngle)) { return(rotateto); } return(null); }
//deprecated public void FlipFinal(float delay = 0f, bool withAnimation = true) { /* #region NEW_ADD * int sceneIndex = UnityEngine.SceneManagement.SceneManager.GetActiveScene ().buildIndex; * if (sceneIndex != (int)EScene.SCENE_Demo) { * return; * } #endregion */ Vector3 oldPos = transform.position; if (withAnimation) { _flipActionList.Clear(); FiniteTimeAction delayTime = null; if (delay > 0f) { delayTime = DelayTime.Create(delay); } //上移 FiniteTimeAction mby = MoveBy.Create(0.2f, Vector3.up * 10f); //翻过来 FiniteTimeAction mbt1 = RotateBy.Create(0.2f, Vector3.forward, 180f, Space.Self); //下移到原来的地方 FiniteTimeAction mbt2 = MoveTo.Create(0.2f, oldPos); FiniteTimeAction mbt3 = MoveTo.Create(0.2f, Vector3.up * 5f); FiniteTimeAction mbt4 = RotateTo.Create(0.2f, Vector3.zero); FiniteTimeAction mbt5 = InvokeAction.Create(delegate(GameObject target, object userdata) { //TableController.Instance.SetCurrentPlayedTile (this); }); if (delayTime != null) { _flipActionList.Add(delayTime); } _flipActionList.Add(mby); _flipActionList.Add(mbt1); _flipActionList.Add(mbt2); _flipActionList.Add(mbt3); _flipActionList.Add(mbt4); _flipActionList.Add(mbt5); ActionManager.Instance.RunAction(gameObject, _flipActionList); } else { //transform.Rotate (Vector3.forward, 180f, Space.Self); transform.rotation = Quaternion.identity; transform.position = Vector3.up * 5f; //TableController.Instance.SetCurrentPlayedTile (this); } }
/// <summary> /// 让指定对象执行RotateTo旋转事件 /// </summary> /// /// <param name="o"></param> /// <param name="angle"></param> /// <param name="speed"></param> /// <returns></returns> public RotateTo CallRotateTo(Loon.Action.ActionBind o, float angle, float speed) { if (isClose) { return(null); } RotateTo rotate = new RotateTo(angle, speed); AddActionEvent(rotate, o); return(rotate); }
// Create and return RotateTo object // targetObj - Object on which the animation clip has to be played // angle - rotation angle // animSpeed - animation speed // loopCount - loopCount for animation public static RotateTo RotateTo(GameObject targetObj, Vector3 angle, float animSpeed, int loopCount, float startDelay = 0.0f) { RotateTo newAnim = new RotateTo(); newAnim.targetObj = targetObj; newAnim.path = new Vector3[3]; // NOTE : Unity always rotates an object in the direction of the acute angle. Therefore, we have to split the path into 3 vectors for rotations // greater than 180 degrees. The intermediate angle is to ensure that if that target angle is 360 degrees, a complete rotation happens instead of // 180 degrees back and forth // Fill same values for (x,y,z) in all the 3 path vectors for rotations less than 180 degrees if (angle.x >= 180) { newAnim.path[0].x = -180; newAnim.path[1].x = angle.x - 360 - 1; newAnim.path[2].x = angle.x - 360; } else { newAnim.path[0].x = newAnim.path[1].x = newAnim.path[2].x = angle.x; } if (angle.y >= 180) { newAnim.path[0].y = -180; newAnim.path[1].y = angle.y - 360 - 1; newAnim.path[2].y = angle.y - 360; } else { newAnim.path[0].y = newAnim.path[1].y = newAnim.path[2].y = angle.y; } if (angle.z >= 180) { newAnim.path[0].z = -180; newAnim.path[1].z = angle.z - 360 - 1; newAnim.path[2].z = angle.z - 360; } else { newAnim.path[0].z = newAnim.path[1].z = newAnim.path[2].z = angle.z; } // newAnim.axis = rotateAround; newAnim.animSpeed = animSpeed; newAnim.loopCount = loopCount; newAnim.startDelay = startDelay; newAnim.curTargetIndex = 0; return(newAnim); }
void rotateToDestination(RotateTo target) { Debug.Log(gameObject.name + " is rotating!"); direction = (target.rotateToObject.transform.position - transform.position).normalized; direction.y = 0; lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)); // flattens the vector3 turnAmt = character.Turn(direction, rotate.speed, false, false); if (turnAmt <= .01f) { rotating = false; rotate.finish(); } transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * target.speed); Debug.Log("Finished Rotation: " + transform.rotation + " && " + target.rotateToObject.transform.rotation); }
virtual public void OnExit() { m_rotateTo = RotateTo.eNone; m_speed = IM.Vector3.zero; m_accelerate = IM.Vector3.zero; m_turningSpeed = IM.Number.zero; m_curExecSkill = null; m_time = IM.Number.zero; if (m_onActionDone != null) { m_onActionDone(); } m_player.m_blockable.Clear(); m_lstActionId.Clear(); }
virtual public void OnEnter(PlayerState lastState) { m_rotateTo = RotateTo.eNone; m_rotateType = RotateType.eDirect; m_speed = IM.Vector3.zero; m_accelerate = IM.Vector3.zero; m_turningSpeed = IM.Number.zero; m_bMoveForward = true; m_playbackSpeed = IM.Number.one; m_curExecSkill = m_player.m_toSkillInstance; if (m_curExecSkill != null) { m_player.m_stamina.ConsumeStamina(new IM.Number((int)m_curExecSkill.skill.levels[m_curExecSkill.level].stama)); } m_time = IM.Number.zero; }
public void Damage() { // 主角与敌人碰撞时(而非踩到了敌人),触发一个旋转动作(其实效果可以做的更有趣一些, // 比如先反弹到某一方向(FireTo),然后再弹回等等,此处仅仅举个例子) if (rotate == null) { // 旋转360度,每帧累加5度 rotate = new RotateTo(360f, 5f); rotate.SetActionListener(new RotateActionListener(this)); AddAction(rotate, hero); } else if (rotate.IsComplete()) { hero.SetFilterColor(LColor.red); // 直接重置rotate对象 rotate.Start(hero); // 重新插入(LGame的方针是Action事件触发且结束后,自动删除该事件,所以需要重新插入) AddAction(rotate, hero); } }
void Update() { if (aiState == 0) { if (gamecontrol.GetDistanceTo(transform.position, gamecontrol.GetPlayerLoc()) < targetRadius) { Move movement = new Move(this, gamecontrol.GetPlayerLoc()); movement.Execute(); } else { aiState += 1; } } else { RotateAround rot = new RotateAround(this, 200, gamecontrol.GetPlayerLoc(), targetRadius); rot.Execute(); RotateTo rot2 = new RotateTo(this, gamecontrol.GetPlayerLoc(), 999); rot2.Execute(); } }
void Start() { // שיוך לקנבס של כל דמות MarioCanvas = Mario.GetComponentInChildren <Canvas>(); PacManCanvas = PacMan.GetComponentInChildren <Canvas>(); PikachuCanvas = Pikachu.GetComponentInChildren <Canvas>(); NurseCanvas = Nurse.GetComponentInChildren <Canvas>(); // שיוך לטקסט בקנבס של כל דמות MarioText = Mario.GetComponentInChildren <Text>(); PacManText = PacMan.GetComponentInChildren <Text>(); PikachuText = Pikachu.GetComponentInChildren <Text>(); NurseText = Nurse.GetComponentInChildren <Text>(); // שיוך לאנימטור של כל דמות MarioAnimator = Mario.GetComponentInChildren <Animator>(); PacManAnimator = PacMan.GetComponentInChildren <Animator>(); GhostAnimator = Ghost.GetComponentInChildren <Animator>(); PikachuAnimator = Pikachu.GetComponentInChildren <Animator>(); // של כל דמות NavMeshAgent שיוך ל PlayerAgent = GetComponent <NavMeshAgent>(); MarioAgent = Mario.GetComponent <NavMeshAgent>(); PacManAgent = PacMan.GetComponent <NavMeshAgent>(); PikachuAgent = Pikachu.GetComponent <NavMeshAgent>(); // של כל דמות NavMeshObstacle שיוך ל MarioNavMeshObstacle = Mario.GetComponent <NavMeshObstacle>(); PacManNavMeshObstacle = PacMan.GetComponentInChildren <NavMeshObstacle>(); PikachuNavMeshObstacle = Pikachu.GetComponent <NavMeshObstacle>(); // יחוס למחלקות אחרות CameraController = Camera.main.GetComponent <CameraController>(); ClickToMove = GetComponent <ClickToMove>(); PickDropObject = GetComponent <PickDropObject>(); RotateTo = GetComponent <RotateTo>(); // StartCoroutine(Test()); // הפעלת פונקציה לבדיקת המשחק }
void Start() { anim = GetComponent <Animator>(); ClickToMove = GetComponent <ClickToMove>(); RotateTo = GetComponent <RotateTo>(); }
// Use this for initialization void Start() { CreateQuests (); //find out all GUI we need to handle player = GameObject.FindWithTag ("Player"); psg = player.GetComponent<PlayerStateGUI> (); skill = player.GetComponent<SkillTree> (); item = player.GetComponent<ItemGUI> (); Q1Script = this.gameObject.GetComponent<Quest1>(); Q2Script = this.gameObject.GetComponent<Quest2>(); Q3Script = this.gameObject.GetComponent<Quest3>(); Q4Script = this.gameObject.GetComponent<Quest4>(); R = GameObject.Find ("Arrow").GetComponent<RotateTo>(); }
public static void MoveCharacter(string direction) { var vector3 = scene1.PrimayCharacter.Location; Vector3 vector = new Vector3(vector3.X, vector3.Y, vector3.Z); if (vector.X % 5f == 0 && vector.Y % 5f == 0 && vector.Z % 5f == 0) { RotateBy rotate = null; RotateTo rotateTo = null; const float distance = 5; const float duration = distance / 5; switch (direction) { case "L": rotateTo = new RotateTo(duration: duration, deltaAngleX: 0, deltaAngleY: 0, deltaAngleZ: 90); vector.X -= distance; break; case "R": rotateTo = new RotateTo(duration: duration, deltaAngleX: 0, deltaAngleY: 0, deltaAngleZ: -90); vector.X += distance; break; case "D": rotate = new RotateBy(duration: duration, deltaAngleX: 0, deltaAngleY: -90, deltaAngleZ: 0); vector.Y -= distance; break; case "U": rotate = new RotateBy(duration: duration, deltaAngleX: 0, deltaAngleY: 90, deltaAngleZ: 0); vector.Y += distance; break; case "B": rotate = new RotateBy(duration: duration, deltaAngleX: 0, deltaAngleY: 0, deltaAngleZ: 0); vector.Z -= distance; break; case "F": rotate = new RotateBy(duration: duration, deltaAngleX: -90, deltaAngleY: 0, deltaAngleZ: 0); vector.Z += distance; break; default: rotate = new RotateBy(duration: duration, deltaAngleX: 90, deltaAngleY: 0, deltaAngleZ: 0); break; } if (scene1.CheckBlockLocationIsEmpty(vector)) { var moveTo = new MoveTo(duration, vector); var ease = GetRandomActionEase(moveTo); scene1.PrimayCharacter.BlockNode.RunActions(ease); //if (rotate == null) //{ // scene1.PrimayCharacter.BlockNode.RunActionsAsync(new Urho.Actions.Parallel(ease, rotateTo)); //} //else //{ // scene1.PrimayCharacter.BlockNode.RunActionsAsync(new Urho.Actions.Parallel(ease, rotate)); //} } } }
virtual public void Update(IM.Number fDeltaTime) { m_time += fDeltaTime; if (m_speed != IM.Vector3.zero || m_accelerate != IM.Vector3.zero) { IM.Vector3 curSpeed = m_speed; if (m_accelerate != IM.Vector3.zero) { m_speed += m_accelerate * fDeltaTime; } if (!m_bMoveForward) { m_player.Move(fDeltaTime, m_speed); } else { IM.Number m_speedMag = m_speed.magnitude; IM.Vector3 m_speedNor = m_speed.normalized; IM.Vector3 vPlayerSpace = m_player.rotation * m_speedMag * m_speedNor; m_player.MoveTowards(m_player.forward, m_turningSpeed, fDeltaTime, vPlayerSpace); } } //rotation if (m_rotateTo != RotateTo.eNone) { IM.Vector3 vRotateTo = IM.Vector3.zero; if (m_rotateTo == RotateTo.eBasket) { vRotateTo = m_basket.m_vShootTarget; } else if (m_rotateTo == RotateTo.eDefenseTarget) { vRotateTo = m_player.m_defenseTarget.position; } else if (m_rotateTo == RotateTo.eBall) { vRotateTo = m_ball.position; } vRotateTo = GameUtils.HorizonalNormalized(vRotateTo, m_player.position); if (m_relAngle != IM.Number.zero) { vRotateTo = IM.Quaternion.AngleAxis(m_relAngle, IM.Vector3.up) * vRotateTo; } if (IM.Vector3.Angle(m_player.forward, vRotateTo) < new IM.Number(0, 100)) { m_rotateTo = RotateTo.eNone; } else { if (m_rotateType == RotateType.eDirect) { m_player.forward = vRotateTo; m_rotateTo = RotateTo.eNone; } else if (m_rotateType == RotateType.eSmooth) { IM.Number step = m_turningSpeed * fDeltaTime; m_player.forward = IM.Vector3.RotateTowards(m_player.forward, vRotateTo, step, IM.Number.zero); } } } if (m_curAction != null && m_curAction.Length > 0 && !m_player.animMgr.IsPlaying(m_curAction)) { _OnActionDone(); } }
public override void Execute() { if (m_DOTweenAction == null) { Debug.LogError("무브 액션이 설정안된 객체입니다. 설정해주시기 바랍니다. 에러객체 이름 및 좌표 : " + m_MonoBehaviour.gameObject.name + " / " + m_MonoBehaviour.gameObject.transform.position); return; } switch (m_DOTweenActionType) { case DOTweenActionType.MoveTo: { MoveTo to = m_DOTweenAction as MoveTo; m_MonoBehaviour.gameObject.transform .DOMove(to.GetEndPoint(), to.GetDuration()) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.MoveBy: { MoveBy by = m_DOTweenAction as MoveBy; m_MonoBehaviour.gameObject.transform .DOBlendableMoveBy(by.GetEndPoint(), by.GetDuration()) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.MovePaths: { MovePaths paths = m_DOTweenAction as MovePaths; m_MonoBehaviour.gameObject.transform .DOPath(paths.GetPaths(), paths.GetDuration(), paths.GetPathType()) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.RotateTo: { RotateTo roateto = m_DOTweenAction as RotateTo; m_MonoBehaviour.gameObject.transform .DORotate(roateto.GetEndPoint(), roateto.GetDuration()) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.RotateBy: { RotateBy roateby = m_DOTweenAction as RotateBy; m_MonoBehaviour.gameObject.transform .DOBlendableLocalRotateBy(roateby.GetEndPoint(), roateby.GetDuration()) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.ColorTo: { ColorTo colorto = m_DOTweenAction as ColorTo; m_MonoBehaviour.gameObject.GetComponentInChildren <MeshRenderer>().material .DOColor(colorto.GetEndPoint(), colorto.GetDuration()) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.ColorRewind: { ColorTo colorto = m_DOTweenAction as ColorTo; Material material = m_MonoBehaviour.gameObject.GetComponentInChildren <MeshRenderer>().material; Color oriColor = material.color; float duration = colorto.GetDuration() / 2; DOTween.Sequence() .Append(material.DOColor(oriColor, duration)) .Append(material.DOColor(colorto.GetEndPoint(), duration)) .OnComplete(() => m_IsCompleted = true); } break; case DOTweenActionType.ScaleTo: { ScaleTo scaleTo = m_DOTweenAction as ScaleTo; m_MonoBehaviour.gameObject.transform .DOScale(scaleTo.GetEndPoint(), scaleTo.GetDuration()) .OnComplete(() => m_IsCompleted = true); } break; } }