本文整理汇总了C#中UnityEngine.Rigidbody.AddRelativeTorque方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.AddRelativeTorque方法的具体用法?C# Rigidbody.AddRelativeTorque怎么用?C# Rigidbody.AddRelativeTorque使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rigidbody
的用法示例。
在下文中一共展示了Rigidbody.AddRelativeTorque方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start () {
// gameController = GameControllerSingleton.get();
rb = GetComponent<Rigidbody>();
rb.AddRelativeTorque(0, initTorque, 0);
rb.AddRelativeForce(0, initYForce, 0);
initY = transform.position.y;
}
示例2: applyAngularForce
public void applyAngularForce(Rigidbody toBody, Vector3 desiredTorque, bool relative)
{
if(relative) {
toBody.AddRelativeTorque(desiredTorque, this.angularForceMode);
}
else {
toBody.AddTorque(desiredTorque, this.angularForceMode);
}
}
示例3: Start
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
rb.velocity = new Vector2(Random.Range(-maxSpeed, maxSpeed), Random.Range(-maxSpeed, maxSpeed));
rb.AddRelativeTorque(Random.Range(0.0f, maxRotation), Random.Range(0.0f, maxRotation), Random.Range(0.0f, maxRotation));
transform.localScale = new Vector3(Random.Range(minScale, maxScale), Random.Range(minScale, maxScale), Random.Range(minScale, maxScale));
rb.mass = rb.mass * transform.localScale.x * transform.localScale.y * transform.localScale.z;
}
示例4: Start
// Use this for initialization
void Start ()
{
//Start spinning
rb = GetComponent<Rigidbody>();
//Spinning might be random on some, could be fixed, use a bool to decide which behaviour to use
if(randomSpin)
{
spinDir = new Vector3(Random.Range(0, 2), Random.Range(0, 2), Random.Range(0, 2)).normalized;
spinForce = Random.Range(10, 100);
}
rb.AddRelativeTorque(spinDir * spinForce * Time.smoothDeltaTime);
}
示例5: Awake
public void Awake()
{
BallRb = GetComponent<Rigidbody>();
//BallRb.useGravity = false;
//BallRb.AddRelativeForce(Vector3.one * 500);
if (startSpeed == 0)
startSpeed = -15.0f;
BallRb.maxAngularVelocity = maxAngularSpeed;
BallRb.AddRelativeTorque(Vector3.one);
BallRb.velocity = new Vector3(0, startSpeed, 0);
grav = new Vector3(0, -9.81f, 0);
playerContact = GameObject.FindGameObjectWithTag("Player").GetComponent<PaddleContact>();
enemyContact = GameObject.FindGameObjectWithTag("Enemy").GetComponent<PaddleContact>();
playerContact.ball = this;
enemyContact.ball = this;
ballAudio = GetComponent<AudioSource>() as AudioSource;
}
示例6: EjectShell
/// <summary>
/// spawns the 'ShellPrefab' gameobject and gives it a velocity
/// </summary>
protected virtual void EjectShell()
{
if (ShellPrefab == null)
return;
// spawn the shell
GameObject s = null;
s = (GameObject)vp_Utility.Instantiate(ShellPrefab,
((m_ShellEjectSpawnPoint == null)
? FirePosition + m_ProjectileSpawnPoint.transform.TransformDirection(ShellEjectPosition) // we have no shell eject object: use old logic
: m_ShellEjectSpawnPoint.transform.position) // we have a shell eject object: use new logic
, m_ProjectileSpawnPoint.transform.rotation);
s.transform.localScale = m_ActualShellScale;
vp_Layer.Set(s.gameObject, vp_Layer.Debris);
// send it flying
m_ShellRigidbody = s.GetComponent<Rigidbody>();
if (m_ShellRigidbody == null)
return;
Vector3 force = ((m_ShellEjectSpawnPoint == null) ?
transform.TransformDirection(ShellEjectDirection).normalized * ShellEjectVelocity // we have a shell eject object: use new logic
: m_ShellEjectSpawnPoint.transform.forward.normalized * ShellEjectVelocity); // we have no shell eject object: use old logic
// toss the shell
m_ShellRigidbody.AddForce(force, ForceMode.Impulse);
// make the shell inherit the current speed of the controller (if any)
if (m_CharacterController) // TODO: should use a velocity calculated from operator transform
{
Vector3 velocityForce = (m_CharacterController.velocity);
m_ShellRigidbody.AddForce(velocityForce, ForceMode.VelocityChange);
}
// add random spin if user-defined
if (ShellEjectSpin > 0.0f)
{
if (Random.value > 0.5f)
m_ShellRigidbody.AddRelativeTorque(-Random.rotation.eulerAngles * ShellEjectSpin);
else
m_ShellRigidbody.AddRelativeTorque(Random.rotation.eulerAngles * ShellEjectSpin);
}
}
示例7: ApplyForce
/// <summary>
/// Applies the force.
/// </summary>
/// <param name="body">The body.</param>
public override void ApplyForce(Rigidbody body) {
var torqueVector = Random.insideUnitSphere * Amount;
body.AddRelativeTorque(torqueVector, ForceMode.Impulse);
}