本文整理汇总了C#中UnityEngine.Rigidbody.AddTorque方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.AddTorque方法的具体用法?C# Rigidbody.AddTorque怎么用?C# Rigidbody.AddTorque使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rigidbody
的用法示例。
在下文中一共展示了Rigidbody.AddTorque方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody> ();
rb.AddForce ((Vector3.up * upVelocity) + (Vector3.left * Random.Range (-pushAmt, pushAmt)) + (Vector3.forward * Random.Range (-pushAmt, pushAmt)));
rb.AddTorque (Vector3.up * Random.Range (-turnAmt, turnAmt));
rb.AddTorque (Vector3.left * Random.Range (-turnAmt, turnAmt));
}
示例2: Start
void Start()
{
if(useRigidbody){
rigidbody = GetComponent<Rigidbody>();
rigidbody.AddTorque(transform.up * torque * (int)turnDirection);
}
}
示例3: Start
void Start()
{
rb = GetComponent<Rigidbody>();
rb.maxAngularVelocity = 1000;
rb.AddTorque(0, speed, 0);
StartCoroutine(PerdaVelocidade());
}
示例4: applyAngularForce
public void applyAngularForce(Rigidbody toBody, Vector3 desiredTorque, bool relative)
{
if(relative) {
toBody.AddRelativeTorque(desiredTorque, this.angularForceMode);
}
else {
toBody.AddTorque(desiredTorque, this.angularForceMode);
}
}
示例5: Shoot
void Shoot()
{
var rotation = Quaternion.AngleAxis (90f, Vector3.forward);
GameObject NuevaBala = Instantiate(balloon, source.transform.position, rotation) as GameObject;
NuevaBala.transform.LookAt(MousePos);
rb = NuevaBala.GetComponent<Rigidbody>();
rb.AddForce( torreta.transform.forward * ShootForce);
rb.AddTorque (Vector3.right * ShootForce);
Destroy(NuevaBala, 5);
}
示例6: Start
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
//rbc = GameObject.Find("redbloodCell");
// add random torque to the RBC so that it is spinning slightly
float tX = Random.Range(-5.0f, 5.0f);
float tY = Random.Range(-5.0f, 5.0f);
float tZ = Random.Range(-5.0f, 5.0f);
Vector3 newTorque = new Vector3 (tX, tY, tZ);
rb.AddTorque(newTorque);
Destroy(gameObject, 20);
}
示例7: Start
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
wbc = GameObject.Find("whiteBloodCell");
//returningPoint = GameObject.FindGameObjectWithTag("returningPoint");
//forceAreaReturn = GameObject.FindGameObjectWithTag("forceAreaReturn");
// add random torque to the WBC so that it is spinning slightly
float tX = Random.Range(-5.0f, 5.0f);
float tY = Random.Range(-5.0f, 5.0f);
float tZ = Random.Range(-5.0f, 5.0f);
Vector3 newTorque = new Vector3(tX, tY, tZ);
rb.AddTorque(newTorque);
}
示例8: Start
// Use this for initialization
void Start()
{
if (directionRight)
{
direction = new Vector3(-1.0f, 1.0f, 0.0f);
offset = new Vector3(1.0f, 2.0f, 0.0f);
} else
{
direction = new Vector3(1.0f, 1.0f, 0.0f);
offset = new Vector3(-2.0f, 2.0f, 0.0f);
}
gameObject.transform.position = player.gameObject.transform.position + offset;
rigidBody = GetComponent<Rigidbody>();
rigidBody.AddForce(direction * thrust, ForceMode.Impulse);
rigidBody.AddTorque(new Vector3(0, 0, rotation), ForceMode.Impulse);
}
示例9: Start
// Use this for initialization
void Start()
{
myRigidBody = GetComponent<Rigidbody>();
myNetworkView = GetComponent<NetworkView>();
myNetworkManager = Camera.main.GetComponent<NetworkManager>();
myRigidBody.maxAngularVelocity = topAngularSpeed;
myRigidBody.AddRelativeForce(fireForce * Vector3.forward);
myRigidBody.AddRelativeForce(Random.Range(-fireRandomForce, fireRandomForce) * Vector3.right);
myRigidBody.AddTorque(Random.Range(-fireRandomTorque, fireRandomTorque) * Vector3.up);
transform.Rotate(Vector3.up, Random.Range(-fireRandomAngle, fireRandomAngle));
if (!myNetworkManager.multiplayerEnabled || myNetworkView.isMine)
{
myTarget = new GameObject("Target");
myTarget.transform.position = Camera.main.GetComponent<ControlsHandler>().mousePosition;
myTarget.transform.parent = Camera.main.GetComponent<ControlsHandler>().target;
}
}
示例10: RotateRigidbody
/// <summary>
/// Rotates the rigidbody.
/// </summary>
/// <returns>
/// True if rigid body is successfully rotated.
/// </returns>
/// <param name='id'>
/// Touch id.
/// </param>
/// <param name='torqueScalar'>
/// Scalar value applied to torque calculation.
/// </param>
/// <param name='rigidbody'>
/// Rigid body to rotate.
/// </param>
public static bool RotateRigidbody(int id, float torqueScalar, Rigidbody rigidbody)
{
bool success = false;
Vector3 axis;
float torque;
if (TouchManager.RotationAxisTorque(id, torqueScalar, out axis, out torque))
{
rigidbody.AddTorque(axis * torque);
success = true;
}
return success;
}
示例11: Update
// Update is called once per frame
void Update()
{
//update text and timers
textOutput.text = count.ToString();
timeSinceClick += Time.deltaTime;
//check for object destruction
if (selected)
{
if (selectedObj == null)
{
selected = false;
return;
}
else
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
selectedObj.transform.position = ray.GetPoint(distToMaintain);
}
}
if (Input.GetMouseButton(0))
{
if (!selected)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hits = Physics.RaycastAll(ray);
foreach (RaycastHit hit in hits)
{
if (hit.collider.gameObject.tag == "Resource")
{
selected = true;
selectedObj = hit.collider.gameObject;
selectedRigidbody = selectedObj.GetComponent<Rigidbody>();
selectedRigidbody.useGravity = false;
selectedRigidbody.AddTorque(selectedObj.transform.position.normalized * 7);
distToMaintain = Vector3.Distance(selectedObj.transform.position, Camera.main.transform.position);
break;
}
}
}
}
else
{
if (selected)
{
selectedRigidbody.useGravity = true;
selectedRigidbody.AddForce(Vector3.down * fallForce);
if (timeSinceClick <= clickTime)
{
Destroy(selectedObj);
count++;
}
}
selected = false;
timeSinceClick = 0.0f;
}
}
示例12: Start
/// <summary>
///
/// </summary>
protected virtual void Start()
{
m_Transform = transform;
m_Rigidbody = rigidbody;
m_Audio = audio;
if (Camera.main != null)
m_CameraMainTransform = Camera.main.transform;
// set the main collider of this gameobject to be a trigger
collider.isTrigger = true;
// some default audio settings
m_Audio.clip = PickupSound;
m_Audio.playOnAwake = false;
m_Audio.minDistance = 3;
m_Audio.maxDistance = 150;
m_Audio.rolloffMode = AudioRolloffMode.Linear;
m_Audio.dopplerLevel = 0.0f;
// store the initial position
m_SpawnPosition = m_Transform.position;
m_SpawnScale = m_Transform.localScale;
RespawnScaleUpDuration = (m_Rigidbody == null) ? Mathf.Abs(RespawnScaleUpDuration) : 0.0f;
// give bob a random start offset if value is not set
if (BobOffset == -1.0f)
BobOffset = Random.value;
if (RecipientTags.Count == 0)
RecipientTags.Add("Player");
if (RemoveDuration != 0.0f)
vp_Timer.In(RemoveDuration, Remove);
if (m_Rigidbody != null)
{
if(RigidbodyForce != Vector3.zero)
m_Rigidbody.AddForce(RigidbodyForce, ForceMode.Impulse);
if(RigidbodySpin != 0.0f)
m_Rigidbody.AddTorque(Random.rotation.eulerAngles * RigidbodySpin);
}
}
示例13: Launch
public void Launch(Rigidbody toLaunch)
{
toLaunch.isKinematic = false;
toLaunch.AddForce (forceToPush * forceMult);
toLaunch.AddTorque (forceToPush * forceMult);
toLaunch.gameObject.GetComponent<Animator> ().SetTrigger ("shrink");
}
示例14: SetRandomTorque
public static void SetRandomTorque(Rigidbody rb, float maxTorque)
{
Vector3 randomTorque = maxTorque * Random.insideUnitSphere;
rb.angularVelocity = Vector3.zero;
rb.AddTorque(randomTorque);
}
示例15: Update
void Update()
{
facingDirection = script.GetFacingDirection ();
// Throw Shuriken left or right
if (amountUsed < 4) {
if (Input.GetKeyDown (KeyCode.I)) {
Clone = Instantiate (ShurikenPrefab, new Vector3 (spawnThrow.transform.position.x, spawnThrow.transform.position.y, -3.0f),
Quaternion.identity) as Rigidbody;
textObject = Instantiate (TextControlPrefab,
new Vector3 (Clone.transform.position.x - 0.414f, Clone.transform.position.y + 0.352f, -3.0f),
Quaternion.identity) as GameObject;
// get first open slot
for (int i = 0; i < Max; i++) {
if (shurikens [i] == null) {
shurikens [i] = Clone.transform;
textControl [i] = textObject.GetComponent<TextMesh> (); // get the TextMesh
textControl [i].text = "O HOLD O"; // set initial so compiler doesnt complain
textPositions [i] = textObject.GetComponent<Transform> (); // get its position
teleportBlast [i] = Clone.GetComponent<ParticleSystem> (); // get its particle system
shurikenScripts [i] = Clone.GetComponent<ShurikenController> (); // get its script
shurikenScripts [i].SetPlaced (false);
// Assign it the appropriate tag
if (i == 0)
Clone.gameObject.tag = "Shuriken0";
else if (i == 1)
Clone.gameObject.tag = "Shuriken1";
else if (i == 2)
Clone.gameObject.tag = "Shuriken2";
else if (i == 3)
Clone.gameObject.tag = "Shuriken3";
break; // found empty slot
}
}
if (facingDirection == Vector2.right) { // Throw to the right
Clone.AddForce (speed * new Vector3 (1.0f, 0.0f, 0.0f));
Clone.AddTorque (new Vector3 (0, 0, -turnSpeed));
} else { // Throw to the left
Clone.AddForce (speed * new Vector3 (-1.0f, 0.0f, 0.0f));
Clone.AddTorque (new Vector3 (0, 0, turnSpeed));
}
amountUsed++;
}
// Place Shuriken at feet
else if (Input.GetKeyDown (KeyCode.J)) {
Clone = Instantiate (ShurikenPrefab, new Vector3 (spawnPlace.transform.position.x, spawnPlace.transform.position.y, -3.0f),
Quaternion.identity) as Rigidbody;
textObject = Instantiate (TextControlPrefab,
new Vector3 (Clone.transform.position.x - 0.414f, Clone.transform.position.y + 0.352f, -3.0f),
Quaternion.identity) as GameObject;
// get first open slot
for (int i = 0; i < Max; i++) {
if (shurikens [i] == null) {
shurikens [i] = Clone.transform;
textControl [i] = textObject.GetComponent<TextMesh> (); // get the TextMesh
textControl [i].text = "O HOLD O"; // set initial so compiler doesnt complain
textPositions [i] = textObject.GetComponent<Transform> (); // get its position
teleportBlast [i] = Clone.GetComponent<ParticleSystem> (); // get its particle system
shurikenScripts [i] = Clone.GetComponent<ShurikenController> (); // get its script
shurikenScripts [i].SetPlaced (true); // this shuriken does not move
// Assign it the appropriate tag
if (i == 0)
Clone.gameObject.tag = "Shuriken0";
else if (i == 1)
Clone.gameObject.tag = "Shuriken1";
else if (i == 2)
Clone.gameObject.tag = "Shuriken2";
else if (i == 3)
Clone.gameObject.tag = "Shuriken3";
break; // found empty slot
}
}
amountUsed++;
}
}
// update Text positions so they allign with shurikens
for (int i = 0; i < Max; i++)
if (shurikens [i] != null) {
textPositions [i].position = new Vector3 (shurikens [i].position.x - 0.414f, shurikens [i].position.y + 0.352f, -3.0f);
// is has parent then position it above it
if (shurikens [i].parent != null)
textPositions [i].position += new Vector3 (0.0f, 1.0f, 0.0f);
// if Enemy on Shuriken Position it below
if (shurikenScripts [i].GetEnemyOnPlaced () != null)
textPositions [i].position -= new Vector3 (0.0f, 0.75f, 0.0f);
//.........这里部分代码省略.........