当前位置: 首页>>代码示例>>C#>>正文


C# Quaternion.SetFromToRotation方法代码示例

本文整理汇总了C#中UnityEngine.Quaternion.SetFromToRotation方法的典型用法代码示例。如果您正苦于以下问题:C# Quaternion.SetFromToRotation方法的具体用法?C# Quaternion.SetFromToRotation怎么用?C# Quaternion.SetFromToRotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Quaternion的用法示例。


在下文中一共展示了Quaternion.SetFromToRotation方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Hit

 void Hit(int damage)
 {
     Vector3 vectorToPlayer = new Vector3(this.transform.position.x - player.transform.position.x, this.transform.position.y - player.transform.position.y, this.transform.position.z - player.transform.position.z);
     Quaternion bloodRotation = new Quaternion();
     bloodRotation.SetFromToRotation (new Vector3(0,0,1), vectorToPlayer);
     Vector3 bloodPosition = new Vector3 (this.transform.position.x, this.transform.position.y+0.5f, this.transform.position.z);
     var bloodEffect = (Instantiate (particleBlood, bloodPosition, bloodRotation) as GameObject);
     Destroy (bloodEffect, 1.0f);
     var bloodStain = (Instantiate (bloodStainEffect, this.transform.position, this.transform.rotation) as GameObject);
     Destroy (bloodStain, 1.0f);
     health -= damage;
     KillCounterScript.Increment ();
 }
开发者ID:JonECG,项目名称:Milo-s-Misadventures,代码行数:13,代码来源:Enemy.cs

示例2: setLimb

    void setLimb(Transform joint, Transform start, Transform end)
    {
        Quaternion limbRotation = new Quaternion();
        Vector3 limbVector = end.position - start.position;

        joint.position = start.position;
        limbRotation.SetFromToRotation(Vector3.up, limbVector.normalized);
        joint.rotation = limbRotation;

        Vector3 limbScale = joint.localScale;
        limbScale.y = getDistanceBetween(start, end) / 2.0f;
        joint.localScale = limbScale;

        joint.Translate(0.0f, limbScale.y, 0.0f);
    }
开发者ID:rehabgame,项目名称:fighton,代码行数:15,代码来源:KinectSkeletonAlt.cs

示例3: CalcNewRotation

    static Quaternion CalcNewRotation(
        Vector3 rightVector,
        Vector3 upVector,
        Vector3 forwardVector,
        float paramLeft,
        float paramRight,
        float paramAbove,
        float paramBelow,
        float paramBehind,
        Quaternion neckRotation,
        Vector3 headPosition,
        Vector3 targetPosition
    )
    {
        Quaternion newHeadRotation_world;
        // 「正面」の方向 (TBody.trsNeck座標系)
        Vector3 headForward_neck = forwardVector;

        // 「正面」の方向(ワールド座標系)
        Vector3 headForward_world = neckRotation * headForward_neck;

        // headから視線目標点への方向 (ワールド座標系。正規化済み)
        Vector3 headToTargetDirection_world = (targetPosition - headPosition).normalized;

        // 現在の「正面」から目標までの角度
        float currentAngle = Vector3.Angle(headForward_world, headToTargetDirection_world);

        // 視線目標点が首から見て真後ろ付近なら、目標方向は正面にする
        if (currentAngle >= paramBehind)
        {
            headToTargetDirection_world = headForward_world;
            currentAngle = Vector3.Angle(headForward_world, headToTargetDirection_world);
        }

        // headから視線目標点への方向 (TBody.trsNeck座標系。正規化済み)
        Vector3 headToTargetDirection_neck = Quaternion.Inverse(neckRotation) * headToTargetDirection_world;

        // headForward(正面)の向きからheadToTargetDirectionの向きへの回転 (TBody.trsNeck座標系)
        Quaternion headForwardToTargetRotation_neck = new Quaternion();
        headForwardToTargetRotation_neck.SetFromToRotation(headForward_neck, headToTargetDirection_neck);

        //  rad : neck座標系の「正面」から見た(投影した)時の目標点の向き (trsNeck XZ 平面)
        float dx = Vector3.Dot(headToTargetDirection_neck, rightVector);
        float dy = Vector3.Dot(headToTargetDirection_neck, upVector);
        float deg = PluginHelper.NormalizeAngle(Mathf.Rad2Deg * Mathf.Atan2(dy, dx));

        // 向きに応じた限界角度を算出
        float angMax = GetMaxAngle(deg, paramLeft, paramRight, paramAbove, paramBelow);

        // 限界角度を超えているか?
        if (currentAngle > angMax)
        {
            // 超えているので補正する
            float a = angMax / currentAngle;
            headForwardToTargetRotation_neck = Quaternion.Slerp(Quaternion.identity, headForwardToTargetRotation_neck, a);
        }

        newHeadRotation_world = neckRotation * headForwardToTargetRotation_neck;

        return newHeadRotation_world;
    }
开发者ID:nnnna,项目名称:cm3d2_plugins_okiba,代码行数:61,代码来源:TBodyMoveHeadAndEyeReplcacement.cs

示例4: originalTbodyMoveHeadAndEyeCallback2

    // 元の MoveHeadAndEye 相当の処理
    void originalTbodyMoveHeadAndEyeCallback2(TBody tbody, ref Vector3 thatHeadEulerAngle, ref Vector3 thatHeadEulerAngleG, ref Vector3 thatEyeEulerAngle)
    {
        TBody that = tbody;
        CameraMain mainCamera = GameMain.Instance.MainCamera;

        // eyeTargetWorldPos:ワールド座標系での視線のターゲット位置
        Vector3 eyeTargetWorldPos = updateEyeTargetPos(tbody);

        // HeadToCamPer:最終的に顔がカメラを向く度合い
        //  0 なら元の頭の向き、1 ならカメラの向き
        if (that.boHeadToCam)
        {
            that.HeadToCamPer += Time.deltaTime * that.HeadToCamFadeSpeed;
        }
        else
        {
            that.HeadToCamPer -= Time.deltaTime * that.HeadToCamFadeSpeed;
        }
        that.HeadToCamPer = Mathf.Clamp01(that.HeadToCamPer);

        that.boChkEye = false;

        originalMoveHead(tbody, ref thatHeadEulerAngle, ref thatHeadEulerAngleG, ref thatEyeEulerAngle, eyeTargetWorldPos);

        if (that.boMAN || that.trsEyeL == null || that.trsEyeR == null)
        {
            return;
        }

        // 目の追従処理
        if (that.boEyeToCam && that.boChkEye)
        {
            Vector3 toDirection2 = Quaternion.Inverse(that.trsHead.rotation) * (eyeTargetWorldPos - that.trsHead.position);
            Quaternion quaternion2 = new Quaternion();
            quaternion2.SetFromToRotation(Vector3.up, toDirection2);
            Vector3 eulerAngles2 = PluginHelper.NormalizeEulerAngles(quaternion2.eulerAngles);
            Vector3 view = Vector3.Normalize(eyeTargetWorldPos - that.trsEyeL.position);
            quaternion2.SetLookRotation(view, Vector3.up);
            Quaternion quaternion3 = quaternion2 * Quaternion.Euler(0.0f, 90f, 0.0f);

            float num = 0.5f;
            if (that.boEyeSorashi)
            {
                num = 0.05f;
            }
            thatEyeEulerAngle = thatEyeEulerAngle * (1f - num) + eulerAngles2 * num;
        }
        else
        {
            thatEyeEulerAngle = thatEyeEulerAngle * 0.95f;
        }

        that.trsEyeL.localRotation = that.quaDefEyeL * Quaternion.Euler(0.0f, thatEyeEulerAngle.x * -0.2f, thatEyeEulerAngle.z * -0.1f);
        that.trsEyeR.localRotation = that.quaDefEyeR * Quaternion.Euler(0.0f, thatEyeEulerAngle.x * 0.2f, thatEyeEulerAngle.z * 0.1f);
    }
开发者ID:nnnna,项目名称:cm3d2_plugins_okiba,代码行数:56,代码来源:TBodyMoveHeadAndEyeReplcacement.cs

示例5: originalMoveHead

    void originalMoveHead(TBody tbody, ref Vector3 thatHeadEulerAngle, ref Vector3 thatHeadEulerAngleG, ref Vector3 thatEyeEulerAngle, Vector3 eyeTargetWorldPos)
    {
        TBody that = tbody;
        //        CameraMain mainCamera = GameMain.Instance.MainCamera;

        // eulerAngles1:顔の正面向きのベクトルから見た、視線ターゲットまでの回転量
        Vector3 eulerAngles1;
        Quaternion quaternion1 = new Quaternion();
        {
            // toDirection1:顔からターゲットを見た向き(顔の座標系)
            Vector3 toDirection1 = Quaternion.Inverse(that.trsNeck.rotation) * (eyeTargetWorldPos - that.trsNeck.position);

            // quaternion1:(0,1,0) (顔の正面向きのベクトル) から見たときの、toDirection1 までの回転量
            quaternion1.SetFromToRotation(Vector3.up, toDirection1);

            eulerAngles1 = PluginHelper.NormalizeEulerAngles(quaternion1.eulerAngles);
        }

        if (that.boHeadToCamInMode)
        {
            // 追従範囲外かどうかを判定
            if (-80.0f >= eulerAngles1.x || eulerAngles1.x >= 80.0f || -50.0f >= eulerAngles1.z || eulerAngles1.z >= 60.0f)
            {
                that.boHeadToCamInMode = false;
            }
        }
        else
        {
            // 追従範囲内かどうかを判定
            if (-60.0f < eulerAngles1.x && eulerAngles1.x < 60.0f && -40.0f < eulerAngles1.z && eulerAngles1.z < 50.0f)
            {
                that.boHeadToCamInMode = true;
            }
        }

        if (that.boHeadToCamInMode)
        {
            // 追従モード
            that.boChkEye = true;
            float num = 0.3f;

            if (eulerAngles1.x > thatHeadEulerAngle.x + 10.0f)
            {
                thatHeadEulerAngleG.x += num;
            }
            else if (eulerAngles1.x < thatHeadEulerAngle.x - 10.0f)
            {
                thatHeadEulerAngleG.x -= num;
            }
            else
            {
                thatHeadEulerAngleG.x *= 0.95f;
            }

            if (eulerAngles1.z > thatHeadEulerAngle.z + 10.0f)
            {
                thatHeadEulerAngleG.z += num;
            }
            else if (eulerAngles1.z < thatHeadEulerAngle.z - 10.0f)
            {
                thatHeadEulerAngleG.z -= num;
            }
            else
            {
                thatHeadEulerAngleG.z *= 0.95f;
            }
        }
        else
        {
            // 自由モード
            float num = 0.1f;
            if (0.0f > thatHeadEulerAngle.x + 10.0)
            {
                thatHeadEulerAngleG.x += num;
            }
            if (0.0f < thatHeadEulerAngle.x - 10.0f)
            {
                thatHeadEulerAngleG.x -= num;
            }
            if (0.0f > thatHeadEulerAngle.z + 10.0f)
            {
                thatHeadEulerAngleG.z += num;
            }
            if (0.0f < thatHeadEulerAngle.z - 10.0f)
            {
                thatHeadEulerAngleG.z -= num;
            }
        }

        thatHeadEulerAngleG *= 0.95f;
        thatHeadEulerAngle += thatHeadEulerAngleG;

        float uScale = 0.4f;
        that.trsHead.localRotation = Quaternion.Slerp(
            that.trsHead.localRotation,
            that.quaDefHead *
                Quaternion.Euler(
                    thatHeadEulerAngle.x * uScale,
                    0.0f,
                    thatHeadEulerAngle.z * uScale),
//.........这里部分代码省略.........
开发者ID:nnnna,项目名称:cm3d2_plugins_okiba,代码行数:101,代码来源:TBodyMoveHeadAndEyeReplcacement.cs

示例6: SetKinectFloorNormal

 public void SetKinectFloorNormal(Vector3 normal)
 {
     kinectFloorNormal = normal.normalized;
     kinectFloorRotator = Quaternion.identity;
     kinectFloorRotator.SetFromToRotation(Vector3.up, kinectFloorNormal);
 }
开发者ID:Zerphed,项目名称:miscellaneous,代码行数:6,代码来源:RUISCoordinateSystem.cs

示例7: setCompassPointForward

 public void setCompassPointForward(Vector3 pForward)
 {
     Quaternion lRotation = new Quaternion();
     lRotation.SetFromToRotation(Vector3.right, pForward);
     compassPointPivot.localRotation = lRotation;
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:6,代码来源:Compass.cs

示例8: Update

    // Update is called once per frame
    void Update()
    {
        arrowUIText.text = numArrows.ToString();

        if(m_State == PlayerState.Dialogue || m_State == PlayerState.Gather) //Unaggro birds if the character is gathering or in dialogue
        {
            if(GameObject.FindGameObjectWithTag("Bird") != null) //if there are any birds in the scene
            {
                GameObject[] birds = GameObject.FindGameObjectsWithTag("Bird");
                foreach (GameObject b in birds)
                {
                    if(b.GetComponent<BirdAI>().GetBirdState() == BirdAI.BirdState.Attack)
                    {
                        b.GetComponent<BirdAI>().enterSafeArea();
                        b.GetComponent<BirdAI>().StopAttacking();
                    }
                }
            }
        }

        if( m_State == PlayerState.Dialogue && Time.timeScale != 0 ) // Make sure the game isn't paused
        {
            m_Animator.SetBool("isWalking", false);
            if( m_Input.InteractButtonPressed() || m_Input.SelectButtonPressed() )
            {
                m_Dialogue.Advance ();
            }
        }
        if (m_State == PlayerState.Interact || m_State == PlayerState.Gather )
        {
            m_Animator.SetBool("isWalking", false);
            if (m_State == PlayerState.Gather)
            {
                m_Animator.SetBool("isAtking", false);
            }
        }
        if ( m_Input.InteractButtonPressed() && gatherFrom != null && m_State != PlayerState.Aim && m_State != PlayerState.Dialogue)
        {
            if (gatherFrom.tag != "arrow" && gatherFrom.GetComponent<Interactable>().GetCanGather() )
            {
                m_Audio.PlayOnce("rustle");
                SetPlayerState(PlayerState.Gather);
                BeginGather();
            }
        }
        if ( m_Input.AimButtonHeld () && m_State != PlayerState.Gather && m_Combat.GetHasBow () )
        {
            m_Animator.SetBool("isWalking", false);
            SetPlayerState ( PlayerState.Aim );
            if (!m_Animator.GetBool("isAiming"))
            {
                m_Animator.SetBool("isAiming", true);
            }
            bow.SetActive(true);
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            pos.z = transform.position.z;
            //face player towards mouse
            Vector3 FacePos = transform.localScale;
            if (pos.x > transform.position.x)
            {
                m_FacingRight = true;
                FacePos.x = -Mathf.Abs(FacePos.x);
            }
            else
            {
                m_FacingRight = false;
                FacePos.x = Mathf.Abs(FacePos.x);
            }
            transform.localScale = FacePos;

            Vector3 dir = pos - bow.transform.position;

            if (transform.localScale.x < 0)
            {
                dir.x = -dir.x;
            }

            Quaternion rotateTo = new Quaternion();

            //TODO clamp the rotation so you cant go over her head
            rotateTo.SetFromToRotation(Vector3.down, dir);

            bow.transform.rotation = rotateTo;
            Vector3 ClampedRotation = new Vector3(
                bow.transform.rotation.eulerAngles.x,
                bow.transform.rotation.eulerAngles.y,
                Mathf.Clamp(bow.transform.rotation.eulerAngles.z, 210, 320)
                );
            Quaternion ClampedQuaternion = Quaternion.Euler(ClampedRotation);
            bow.transform.rotation = ClampedQuaternion;
        }
        else
        {
            bow.SetActive(false);
        }
        if (m_Input.AimButtonReleased() && m_State == PlayerState.Aim)
        {
            m_Animator.SetBool("isAiming", false);
        }
//.........这里部分代码省略.........
开发者ID:Mitsukizzy,项目名称:Archipelago,代码行数:101,代码来源:Character.cs

示例9: updateArrow

 void updateArrow()
 {
     var lPosition = (beginPosition + endPosition)/2f;
     transform.position = lPosition;
     var lBeginToEnd = endPosition -  beginPosition;
     var lRotation = new Quaternion();
     lRotation.SetFromToRotation(Vector3.up, lBeginToEnd);
     transform.rotation = lRotation;
 }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:9,代码来源:zzWayPointLine.cs

示例10: Rotate

    void Rotate()
    {
        Vector3 lastDirectionInGlobal = _camera.ScreenPointToRay(rightFingerLastPoint).direction;
        Vector3 currentDirectionInGlobal = _camera.ScreenPointToRay(rightFingerCurrentPoint).direction;

        Quaternion rotation = new Quaternion();
        rotation.SetFromToRotation(lastDirectionInGlobal, currentDirectionInGlobal);

        ownTransform.rotation = ownTransform.rotation * Quaternion.Euler(0, kInverse ? rotation.eulerAngles.y : -rotation.eulerAngles.y, 0);

        // and now the rotation in the camera's local space
        rotation.SetFromToRotation(	cameraTransform.InverseTransformDirection(lastDirectionInGlobal),
                                   cameraTransform.InverseTransformDirection(currentDirectionInGlobal));
        cameraTransform.localRotation = Quaternion.Euler(kInverse ? rotation.eulerAngles.x : -rotation.eulerAngles.x, 0, 0) * cameraTransform.localRotation;

        rightFingerLastPoint = rightFingerCurrentPoint;
    }
开发者ID:tinyminds,项目名称:glomp,代码行数:17,代码来源:TapMoveDragLook.cs

示例11: attachToPoints

	protected void attachToPoints(Vector3 start, Vector3 end)
	{
		if (mNodes.Length > 0)
		{
			Vector3 pathStart = mNodes[0].localPosition;
			Vector3 pathEnd = mNodes[mNodes.Length - 1].localPosition;

			Vector3 pathDirection = pathEnd - pathStart;
			Vector3 attachDirection = end - start;

			Quaternion rotation = new Quaternion();
			rotation.SetFromToRotation(pathDirection, attachDirection);

			transform.rotation = rotation;

			float scale = attachDirection.magnitude / pathDirection.magnitude;

			transform.localScale = new Vector3(scale, scale, scale);

			//Vector3 offset = mNodes[0].position - start;

			transform.position = start - (mNodes[0].position - transform.position);
		}
	}
开发者ID:NerdsRUs,项目名称:Summer2014,代码行数:24,代码来源:TimelineEventPath.cs


注:本文中的UnityEngine.Quaternion.SetFromToRotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。