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


C# Vector3.Normalize方法代码示例

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


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

示例1: GetAngleAxis

        public static void GetAngleAxis(this Quaternion q, out Vector3 axis, out float angle)
        {
            if (q.w > 1) q = QuaternionUtil.Normalize(q);

            //get as doubles for precision
            var qw = (double)q.w;
            var qx = (double)q.x;
            var qy = (double)q.y;
            var qz = (double)q.z;
            var ratio = System.Math.Sqrt(1.0d - qw * qw);

            angle = (float)(2.0d * System.Math.Acos(qw)) * Mathf.Rad2Deg;
            if (ratio < 0.001d)
            {
                axis = new Vector3(1f, 0f, 0f);
            }
            else
            {
                axis = new Vector3(
                    (float)(qx / ratio),
                    (float)(qy / ratio),
                    (float)(qz / ratio));
                axis.Normalize();
            }
        }
开发者ID:yuanchunfa,项目名称:spacepuppy-unity-framework,代码行数:25,代码来源:QuaternionUtil.cs

示例2: GetShortestAngleAxisBetween

        public static void GetShortestAngleAxisBetween(Quaternion a, Quaternion b, out Vector3 axis, out float angle)
        {
            var dq = Quaternion.Inverse(a) * b;
            if (dq.w > 1) dq = QuaternionUtil.Normalize(dq);

            //get as doubles for precision
            var qw = (double)dq.w;
            var qx = (double)dq.x;
            var qy = (double)dq.y;
            var qz = (double)dq.z;
            var ratio = System.Math.Sqrt(1.0d - qw * qw);

            angle = (float)(2.0d * System.Math.Acos(qw)) * Mathf.Rad2Deg;
            if (ratio < 0.001d)
            {
                axis = new Vector3(1f, 0f, 0f);
            }
            else
            {
                axis = new Vector3(
                    (float)(qx / ratio),
                    (float)(qy / ratio),
                    (float)(qz / ratio));
                axis.Normalize();
            }
        }
开发者ID:yuanchunfa,项目名称:spacepuppy-unity-framework,代码行数:26,代码来源:QuaternionUtil.cs

示例3: Project

 public AxisInterval Project(Vector3 axis)
 {
     axis.Normalize();
     var a = Vector3.Dot(this.Min, axis);
     var b = Vector3.Dot(this.Max, axis);
     return new AxisInterval(axis, a, b);
 }
开发者ID:Gege00,项目名称:spacepuppy-unity-framework,代码行数:7,代码来源:AABBox.cs

示例4: Move

        public void Move(Vector3 move, bool crouch, bool jump)
        {
            if (move.magnitude > 1f)
                move.Normalize ();

            move = transform.InverseTransformDirection (move);
            CheckGroundStatus ();

            move = gravityRotation * move;
            move = Vector3.ProjectOnPlane (move, m_GroundNormal);

            float z = Vector3.Dot (move, gravityForward);
            float x = Vector3.Dot (move, gravityRight);

            m_TurnAmount = Mathf.Atan2 (x, z);
            m_ForwardAmount = z;

            ApplyExtraTurnRotation ();

            // control and velocity handling is different when grounded and airborne:
            if (m_IsGrounded) {
                HandleGroundedMovement (crouch, jump);
            } else {
                HandleAirborneMovement ();
            }

            ScaleCapsuleForCrouching (crouch);
            PreventStandingInLowHeadroom ();

            UpdateAnimator(move);
        }
开发者ID:OtagoOpenSource,项目名称:GamesRepo,代码行数:31,代码来源:ThirdPersonCharacter.cs

示例5: Move

        public void Move(Vector3 move, bool crouch, bool jump)
        {
            // convert the world relative moveInput vector into a local-relative
            // turn amount and forward amount required to head in the desired
            // direction.
            if (move.magnitude > 1f) move.Normalize();
            move = transform.InverseTransformDirection(move);
            CheckGroundStatus();
            move = Vector3.ProjectOnPlane(move, m_GroundNormal);
            m_TurnAmount = Mathf.Atan2(move.x, move.z);
            m_ForwardAmount = move.z;

            ApplyExtraTurnRotation();

            // control and velocity handling is different when grounded and airborne:
            if (m_IsGrounded)
            {
                HandleGroundedMovement(crouch, jump);
            }
            else
            {
                HandleAirborneMovement();
            }

            ScaleCapsuleForCrouching(crouch);
            PreventStandingInLowHeadroom();

            // send input and other state parameters to the animator
            UpdateAnimator(move);
        }
开发者ID:ian-h-chamberlain,项目名称:rise-and-fall,代码行数:30,代码来源:ThirdPersonCharacter.cs

示例6: Update

        void Update()
        {
            if(!m_IsHitTarget)
            {
                // 通过距离判断是否打到
                float dist = Vector3.Distance(m_Target.transform.position, transform.position);
                if(dist <= 2.0f)
                {
                    m_IsHitTarget = true;
                    // 击中目标,产生震屏效果
                    ThirdPersonCamera.OnShakeCamera();

                    // 播放击中的粒子特效
                    m_HitEffect.transform.position = m_Target.GetComponent<EnemyControl>().GetHitPos();;
                    m_HitEffect.GetComponent<ParticleSystem>().Play();
                    return;
                }

                m_OriY = transform.position.y;
                m_TempVec3 = m_Target.transform.position - transform.position;
                m_TempVec3.Normalize();
                m_TempVec3 = transform.position + m_TempVec3*m_Speed*Time.deltaTime;
                m_TempVec3.y = m_OriY;

                transform.position = m_TempVec3;
            }
        }
开发者ID:spiritpig,项目名称:3DGame,代码行数:27,代码来源:MagicBallControl.cs

示例7: Move

		public bool Move(Vector3 move, bool crouch, bool jump)
		{

			// convert the world relative moveInput vector into a local-relative
			// turn amount and forward amount required to head in the desired
			// direction.
			if (move.magnitude > 1f) move.Normalize();	//serve per limitare la velocità di movimento
			move = transform.InverseTransformDirection(move);
			CheckGroundStatus();
			move = Vector3.ProjectOnPlane(move, m_GroundNormal);
			m_TurnAmount = Mathf.Atan2(move.x, move.z);
			m_ForwardAmount = move.z;

			ApplyExtraTurnRotation();

			// control and velocity handling is different when grounded and airborne:
			if (m_IsGrounded)
			{                
               	DJump = HandleGroundedMovement(crouch, jump, DJump); 	//controlla il movimento a terra
			}
			else
			{                
				DJump = HandleAirborneMovement(jump,DJump);		//controlla il movimento in aria
			}
            
			ScaleCapsuleForCrouching(crouch);		//ridimensiona il collider(?) per quando si è accovacciati
			PreventStandingInLowHeadroom();			//impedisce di stare in piedi dove non puoi

			// send input and other state parameters to the animator
			UpdateAnimator(move);
			return morte;
		}
开发者ID:GynoPyno,项目名称:Project-Pandality,代码行数:32,代码来源:ThirdPersonCharacter.cs

示例8: tick

		public override bool tick()
		{
			if( _isPaused )
				return false;

			if( Mathf.Abs( _shakeIntensity ) > 0f )
			{
				_shakeOffset = _shakeDirection;
				if( _shakeOffset != Vector3.zero )
				{
					_shakeOffset.Normalize();
				}
				else
				{
					_shakeOffset.x += Random.Range( 0f, 1f ) - 0.5f;
					_shakeOffset.y += Random.Range( 0f, 1f ) - 0.5f;
				}

				_shakeOffset *= _shakeIntensity;
				_shakeIntensity *= -_shakeDegredation;
				if( Mathf.Abs( _shakeIntensity ) <= 0.01f )
					_shakeIntensity = 0f;

				_cameraTransform.position += _shakeOffset;

				return false;
			}

			_isCurrentlyManagedByZestKit = false;
			return true;
		}
开发者ID:buddingmonkey,项目名称:WBS99,代码行数:31,代码来源:CameraShakeTween.cs

示例9: MoveTowards

        // Dir is world space direction.
        public void MoveTowards(Vector3 dir)
        {
            // We are not holding a button, so stop rotating.
            if (dir == Vector3.zero) {
            _rb.angularVelocity = dir;
            _rb.velocity = dir;
            return;
            }

            dir.y = 0.0f;
            dir.Normalize();

            Vector3 forward = transform.forward;
            Vector3 right = transform.right;

            forward.y = right.y = 0.0f;
            forward.Normalize();
            right.Normalize();

            float angle = Vector3.Angle(forward, dir);
            float direction = (Vector3.Dot(right, dir) > 0.0f) ? 1.0f : -1.0f;

            if (angle < snapAngle) {
            // If I use Mathf.Deg2Rad here, I get some stuttering, even though Vector3.Angle() returns degrees. :/
            _rb.angularVelocity = new Vector3(0.0f, angle * direction, 0.0f);
            } else {
            _rb.angularVelocity = new Vector3(0.0f, angularSpeed * direction * Mathf.Deg2Rad, 0.0f);
            }

            if (moveDirSeparateFromAngle) {
            _rb.velocity = dir * speed;
            } else {
            _rb.velocity = transform.forward * speed;
            }
        }
开发者ID:FreezeDriedGames,项目名称:Avocation,代码行数:36,代码来源:ThirdPersonMovementController.cs

示例10: GravityAffector

 public GravityAffector(GAFTTYPE gtype, bool isacc, Vector3 dir, EffectNode node)
     : base(node, AFFECTORTYPE.GravityAffector)
 {
     GType = gtype;
     Dir = dir;
     Dir.Normalize();
     IsAccelerate = isacc;
 }
开发者ID:markofevil3,项目名称:SlotMachine,代码行数:8,代码来源:GravityAffector.cs

示例11: FallForce

		void FallForce(Vector3 vector, Vector3 rotation)
		{
			rotation.x -= 90;
			components.eulerAngles = rotation;
			vector.Normalize();
			vector.y = 1;
			components.AddForce(vector * -1f, ForceMode.VelocityChange);
		}
开发者ID:K-Yoshiki,项目名称:menko,代码行数:8,代码来源:AttackerMenko.cs

示例12: PointFromPercent

        public static Vector3 PointFromPercent(float percent, Vector3[] positions)
        {
            Vector3 sideDir = new Vector3(0,0,1);
            Vector3 vForward = Interpolation(positions,(percent+0.001f));
            Vector3 vBack = Interpolation(positions,(percent-0.001f));
            Vector3 nextDir = vForward - vBack;
            sideDir = YVectorRotate(nextDir, 90.0f);
            sideDir.Normalize();

            return nextDir;
        }
开发者ID:skat2006,项目名称:iRunner,代码行数:11,代码来源:iRunner.cs

示例13: GravityAffector

 public GravityAffector(Transform obj, GAFTTYPE gtype, MAGTYPE mtype,bool isacc, Vector3 dir, float mag,AnimationCurve curve,EffectNode node)
     : base(node, AFFECTORTYPE.GravityAffector)
 {
     GType = gtype;
     MType = mtype;
     Magnitude = mag;
     MagCurve = curve;
     Dir = dir;
     Dir.Normalize();
     GravityObj = obj;
     IsAccelerate = isacc;
 }
开发者ID:sylafrs,项目名称:rugby,代码行数:12,代码来源:GravityAffector.cs

示例14: CalculateNormal

        /// <summary>
        /// Calculate the normal at the given position.
        /// </summary>
        /// <param name="pos">The position.</param>
        /// <returns>The normal.</returns>
        private Vector3 CalculateNormal(Vector3I pos)
        {
            byte x0 = this.terrain.GetDensity(pos - Vector3I.UnitX);
            byte x1 = this.terrain.GetDensity(pos + Vector3I.UnitX);
            byte y0 = this.terrain.GetDensity(pos - Vector3I.UnitY);
            byte y1 = this.terrain.GetDensity(pos + Vector3I.UnitY);
            byte z0 = this.terrain.GetDensity(pos - Vector3I.UnitZ);
            byte z1 = this.terrain.GetDensity(pos + Vector3I.UnitZ);

            Vector3 normal = new Vector3((x1 - x0) * 0.5f, (y1 - y0) * 0.5f, (z1 - z0) * 0.5f);
            normal.Normalize();
            return normal;
        }
开发者ID:andynygard,项目名称:game-dwarves,代码行数:18,代码来源:TerrainMeshBuilder.cs

示例15: BombAffector

 public BombAffector(Transform obj, BOMBTYPE gtype, MAGTYPE mtype,BOMBDECAYTYPE dtype, float mag, AnimationCurve curve,
     float decay, Vector3 axis, EffectNode node)
     : base(node, AFFECTORTYPE.BombAffector)
 {
     BombType = gtype;
     MType = mtype;
     DecayType = dtype;
     Magnitude = mag;
     MagCurve = curve;
     Decay = decay;
     BombAxis = axis;
     BombAxis.Normalize();
     BombObj = obj;
 }
开发者ID:hibaby,项目名称:wowboss,代码行数:14,代码来源:BombAffector.cs


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