Axiom.Samples.CharacterSample.SinbadCharacterController.UpdateBody C# (CSharp) Метод

UpdateBody() приватный Метод

private UpdateBody ( Real deltaTime ) : void
deltaTime Real
Результат void
		private void UpdateBody( Real deltaTime )
		{
			// we will calculate this
			goalDirection = Vector3.Zero;

			if ( keyDirection != Vector3.Zero && baseAnimID != AnimationID.Dance )
			{
				// calculate actually goal direction in world based on player's key directions
				goalDirection += keyDirection.z * cameraNode.Orientation.ZAxis;
				goalDirection += keyDirection.x * cameraNode.Orientation.XAxis;
				goalDirection.y = 0;
				goalDirection.Normalize();

				Quaternion toGoal = bodyNode.Orientation.ZAxis.GetRotationTo( goalDirection );
				// calculate how much the character has to turn to face goal direction
				Real yawToGlobal = toGoal.Yaw;
				// this is how much the character CAN turn this frame
				Real yawAtSpeed = yawToGlobal / Utility.Abs( yawToGlobal ) * deltaTime * TurnSpeed;
				// reduce "turnability" if we're in midair
				if ( baseAnimID == AnimationID.JumpLoop )
					yawAtSpeed *= 0.2;

				// turn as much as we can, but not more than we need to
				if ( yawToGlobal < 0 )
					yawToGlobal = Utility.Min<Real>( yawToGlobal, yawAtSpeed );
				else if ( yawToGlobal > 0 )
					yawToGlobal = Utility.Max<Real>( 0, Utility.Min<Real>( yawToGlobal, yawAtSpeed ) );

				bodyNode.Yaw( yawToGlobal );

				// move in current body direction (not the goal direction)
				bodyNode.Translate( new Vector3( 0, 0, deltaTime * RunSpeed * anims[ (int)baseAnimID ].Weight ), TransformSpace.Local );
			}

			if ( baseAnimID == AnimationID.JumpLoop )
			{
				// if we're jumping, add a vertical offset too, and apply gravity
				bodyNode.Translate( new Vector3( 0, verticalVelocity * deltaTime, 0 ), TransformSpace.Local );
				verticalVelocity -= Gravity * deltaTime;

				Vector3 pos = bodyNode.Position;
				if ( pos.y <= CharHeight )
				{
					// if we've hit the ground, change to landing state
					pos.y = CharHeight;
					bodyNode.Position = pos;
					SetBaseAnimation( AnimationID.JumpEnd, true );
					timer = 0;
				}
			}
		}