本文整理汇总了C#中Quaternion类的典型用法代码示例。如果您正苦于以下问题:C# Quaternion类的具体用法?C# Quaternion怎么用?C# Quaternion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Quaternion类属于命名空间,在下文中一共展示了Quaternion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGrappleBeam
public bool IsHoldingGrapple = false; // if true the player is pulled alongwith the hook shot
public void CreateGrappleBeam() {
if (!IsGrappling) {
HandPosition = transform.position; // default for now
RaycastHit hit;
Player MyPlayer = gameObject.GetComponent<Player> ();
if (Physics.Raycast (transform.position, MyPlayer.ShootForwardVector, out hit, 100)) {
HandPosition = hit.point;
Quaternion NewRotation = new Quaternion ();
//NewRotation.eulerAngles = (hit.point - gameObject.transform.position);
NewRotation.eulerAngles = MyPlayer.ShootForwardVector;
NewRotation = Quaternion.identity;
//Debug.LogError ("Angle of Grapple: " + NewRotation.eulerAngles.ToString());
GameObject MyChain = (GameObject)Instantiate (GrappleBeamPrefab, HandPosition, NewRotation);
//NewRotation = MyChain.transform.rotation;
MyChain.transform.LookAt(hit.point);
//Debug.LogError ("Angle of Grapple: " + MyChain.transform.rotation.eulerAngles.ToString());
if (IsHoldingGrapple) {
//MyChain.transform.rotation = NewRotation;
transform.position = MyChain.transform.GetChild (7).transform.position;
Vector3 CharacterBodyOffset = new Vector3(0,-1.5f,0);
transform.position = transform.position+CharacterBodyOffset;
gameObject.AddComponent<FixedJoint> ();
gameObject.GetComponent<FixedJoint> ().connectedBody = MyChain.transform.GetChild (7).GetComponent<Rigidbody> ();
gameObject.GetComponent<CharacterController> ().enabled = false;
IsGrappling = true;
gameObject.GetComponent<Rigidbody>().isKinematic = false;
}
}
}
}
示例2: AddAvatar
public override PhysicsCharacter AddAvatar(string avName, Vector3 position, Quaternion rotation, Vector3 size,
bool isFlying, uint localID, UUID UUID)
{
BasicCharacterActor act = new BasicCharacterActor {Position = position, Flying = isFlying};
_actors.Add(act);
return act;
}
示例3: Fire
public override void Fire(Vector3 direction, Quaternion rotation)
{
currentDistance = 0;
base.Fire(direction,rotation);
BulletProjectileUp();
amIFired = true;
}
示例4: FindAttributes
void FindAttributes()
{
getRecordedData = false;
GhostPathRecorder temp = GameObject.FindObjectOfType<GhostPathRecorder>();
if( temp == null ) {
Debug.LogError( "TestLerp coulnd't find a GhostPathRecorder in he scene." );
return;
}
if( temp.recordedPositions.Count < 1 || temp.recordedYRotations.Count < 1 ) {
Debug.LogError( "The GhostPathRecorder that TestLerp found has too little sampled positions/rotations to work." );
return;
}
positions = temp.recordedPositions;
yRotations = temp.recordedYRotations;
sampleRate = temp.sampleRate;
thisTransform.position = positions[0];
thisTransform.rotation = Quaternion.Euler( new Vector3( 0f, yRotations[0], 0f ) );
currentStartPos = positions[0];
currentEndPos = positions[1];
currentStartRot = Quaternion.Euler( new Vector3( 0f, yRotations[0], 0f ) );
currentEndRot = Quaternion.Euler( new Vector3( 0f, yRotations[1], 0f ) );
isMoving = true;
getRecordedData = false;
}
示例5: ControlMouse
void ControlMouse()
{
Vector3 mousePos = Input.mousePosition;
mousePos = cam.ScreenToWorldPoint (new Vector3 (mousePos.x, mousePos.y,cam.transform.position.y - transform.position.y));
targetRotation = Quaternion.LookRotation (mousePos - new Vector3(transform.position.x,0,transform.position.z));
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, AimingSpeed ) ;
}
示例6: GetBearingToTarget
protected override void GetBearingToTarget(Vector3 targetPosition)
{
base.GetBearingToTarget(targetPosition);
Vector3 bearingToTarget = targetPosition - transform.position;
targetBearing = Quaternion.LookRotation(bearingToTarget);
}
示例7: Update
// Update is called once per frame
void Update()
{
if (Target == null)return;
//find the vector pointing from our position to the target
_direction = (Target.position - transform.position).normalized;
float step = RotationSpeed * Time.deltaTime;
//create the rotation we need to be in to look at the target
_lookRotation = Quaternion.LookRotation(_direction, Vector3.up);
////rotate us over time according to speed until we are in the required rotation
// if (Vector3.Angle (transform.rotation.eulerAngles, _lookRotation.eulerAngles) < minimumFireAngle && Target != null)
// {
// TagetAligned = true;
// }
// else
// {
// TagetAligned = false;
// }
//
// BroadcastMessage("TagetAlignedStatus", this, SendMessageOptions.DontRequireReceiver);
transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, step);
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, 0f);
Vector3 newDir = Vector3.RotateTowards(transform.forward, _direction, step, 0.0F);
Debug.DrawRay(transform.position, newDir * 50, Color.red);
}
示例8: Update
// Update is called once per frame
void Update()
{
// Rotate the pickup
Quaternion q = new Quaternion();
q.eulerAngles = new Vector3 (0, Time.time*60, Mathf.Sin (Time.time*2) * 10);
transform.localRotation = q;
// Check if the pickup is near one of the players
GameObject player1 = GameObject.Find ("Player1");
GameObject player2 = GameObject.Find ("Player2");
if( player1 != null )
{
if( (player1.transform.position - this.transform.position).magnitude < 2 )
{
GUIManager.currentScore += 100;
Destroy(this.gameObject);
}
}
if( player2 != null )
{
if( (player2.transform.position - this.transform.position).magnitude < 2 )
{
GUIManager.currentScore += 100;
Destroy(this.gameObject);
}
}
}
示例9: Update
// Update is called once per frame
void Update()
{
if (target != null) {
look = Quaternion.LookRotation (target.transform.position - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, look, Time.deltaTime * 8.0F);
}
}
示例10: Enemy
public Enemy(int anID, string aName, Vector3 aPos, Quaternion aRot)
{
base.setID(anID);
base.setName(aName);
position = aPos;
rotation = aRot;
}
示例11: LookRotation
public void LookRotation(Transform character, Transform camera)
{
/*if(i >0) Check for controllers
yRot = Input.GetAxis ("Mouse X") * XSensitivity;
xRot = Input.GetAxis ("Mouse Y") * YSensitivity;
}*/
float deadzone = 0.25f;
Vector2 stickInput = new Vector2(Input.GetAxis("Mouse Y") *YSensitivity, Input.GetAxis("Mouse X") *XSensitivity);
if(stickInput.magnitude < deadzone)
stickInput = Vector2.zero;
else
stickInput = stickInput.normalized * ((stickInput.magnitude - deadzone) / (1 - deadzone));
m_CharacterTargetRot *= Quaternion.Euler (0f, stickInput.y, 0f);
m_CameraTargetRot *= Quaternion.Euler (-stickInput.x, 0f, 0f);
if (clampVerticalRotation) {
m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
}
if(smooth)
{
character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
smoothTime * Time.deltaTime);
camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
smoothTime * Time.deltaTime);
}
else
{
character.localRotation = m_CharacterTargetRot;
camera.localRotation = m_CameraTargetRot;
}
}
示例12: PlaneEqualsTest
public void PlaneEqualsTest()
{
Plane a = new Plane(1.0f, 2.0f, 3.0f, 4.0f);
Plane b = new Plane(1.0f, 2.0f, 3.0f, 4.0f);
// case 1: compare between same values
object obj = b;
bool expected = true;
bool actual = a.Equals(obj);
Assert.Equal(expected, actual);
// case 2: compare between different values
b.Normal = new Vector3(10.0f, b.Normal.Y, b.Normal.Z);
obj = b;
expected = false;
actual = a.Equals(obj);
Assert.Equal(expected, actual);
// case 3: compare between different types.
obj = new Quaternion();
expected = false;
actual = a.Equals(obj);
Assert.Equal(expected, actual);
// case 3: compare against null.
obj = null;
expected = false;
actual = a.Equals(obj);
Assert.Equal(expected, actual);
}
示例13: Start
// Use this for initialization
void Start()
{
//leftArm.transform.eulerAngles = new Vector3(0f, 0f, 90f);
leftArmTargetRotation = Quaternion.Euler(0f, 0f, 90f);
//leftArmTargetRotation = Quaternion.Euler(0f, 0f, 80f);
leftArmState = 1;
//rightArm.transform.eulerAngles = new Vector3(0f, 0f, -90f);
rightArmTargetRotation = Quaternion.Euler(0f, 0f, -90f);
//rightArmTargetRotation = Quaternion.Euler(0f, 0f, -80f);
rightArmState = 1;
//leftLeg.transform.eulerAngles = new Vector3(0f, 0f, 0f);
leftLegTargetRotation = Quaternion.Euler(0f, 0f, 0f);
leftLegState = 1;
//rightLeg.transform.eulerAngles = new Vector3 (0f, 0f, 0f);
rightLegTargetRotation = Quaternion.Euler(0f, 0f, 0f);
rightLegState = 1;
/*
leftArmDown.SetActive(true);
leftArmState = 1;
rightArmDown.SetActive(true);
rightArmState = 1;
leftLegDown.SetActive (true);
leftLegState = 1;
rightLegDown.SetActive (true);
rightLegState = 1;
*/
}
示例14: OnUpdate
protected override void OnUpdate(float factor, bool isFinished)
{
if (this.to != null)
{
if (this.mTrans == null)
{
this.mTrans = base.transform;
this.mPos = this.mTrans.position;
this.mRot = this.mTrans.rotation;
this.mScale = this.mTrans.localScale;
}
if (this.from != null)
{
this.mTrans.position = this.from.position * (1f - factor) + this.to.position * factor;
this.mTrans.localScale = this.from.localScale * (1f - factor) + this.to.localScale * factor;
this.mTrans.rotation = Quaternion.Slerp(this.from.rotation, this.to.rotation, factor);
}
else
{
this.mTrans.position = this.mPos * (1f - factor) + this.to.position * factor;
this.mTrans.localScale = this.mScale * (1f - factor) + this.to.localScale * factor;
this.mTrans.rotation = Quaternion.Slerp(this.mRot, this.to.rotation, factor);
}
if (this.parentWhenFinished && isFinished)
{
this.mTrans.parent = this.to;
}
}
}
示例15: CreateFromQuaternion
public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix3x3 result)
{
float qX2 = quaternion.X + quaternion.X;
float qY2 = quaternion.Y + quaternion.Y;
float qZ2 = quaternion.Z + quaternion.Z;
float XX = qX2 * quaternion.X;
float YY = qY2 * quaternion.Y;
float ZZ = qZ2 * quaternion.Z;
float XY = qX2 * quaternion.Y;
float XZ = qX2 * quaternion.Z;
float XW = qX2 * quaternion.W;
float YZ = qY2 * quaternion.Z;
float YW = qY2 * quaternion.W;
float ZW = qZ2 * quaternion.W;
result.X = new Vector3(
1 - YY - ZZ,
XY + ZW,
XZ - YW);
result.Y = new Vector3(
XY - ZW,
1 - XX - ZZ,
YZ + XW);
result.Z = new Vector3(
XZ + YW,
YZ - XW,
1 - XX - YY);
}