本文整理汇总了C#中UnityEngine.Rigidbody2D.AddTorque方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody2D.AddTorque方法的具体用法?C# Rigidbody2D.AddTorque怎么用?C# Rigidbody2D.AddTorque使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rigidbody2D
的用法示例。
在下文中一共展示了Rigidbody2D.AddTorque方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start() {
aiai = GetComponent<Rigidbody2D> ();
Vector2 dytt = new Vector2 (Random.Range (-100.0f, 100.0f),
Random.Range (-100.0f, 100.0f));
aiai.AddTorque(Random.Range(-100.0f, 100.0f));
aiai.AddForce (dytt, ForceMode2D.Impulse);
}
示例2: Die
public virtual void Die(Rigidbody2D rb)
{
rb.fixedAngle = false;
// rb.AddForce (new Vector2(Random.Range(3,4),Random.Range(40,80)));
// rb.AddForce (new Vector2(4,50f));
rb.gravityScale = 7;
rb.AddTorque(30f);
gameObject.GetComponent<CircleCollider2D> ().isTrigger = true;
// Invoke ("DestroyObject",5f);
}
示例3: OnEnable
public override void OnEnable()
{
base.OnEnable();
m_rigidbody2D = GetComponent<Rigidbody2D>();
m_rigidbody2D.AddTorque(Random.Range(-100, 100));
CurrentHealth = MaxHealth;
if(sprites.Length > 0)
GetComponent<SpriteRenderer>().sprite = sprites[Random.Range(0, sprites.Length)];
}
示例4: Start
// Use this for initialization
void Start()
{
// Set random motion at start.
float torque = Random.Range(100, 1000);
float sign = Mathf.Sign(Random.value - 0.5f);
Vector2 vector = Random.insideUnitCircle;
_rigidbody = GetComponent<Rigidbody2D>();
_rigidbody.AddTorque(torque * sign, ForceMode2D.Force);
_rigidbody.AddForce(vector * 100, ForceMode2D.Force);
}
示例5: Start
// Use this for initialization
void Start()
{
attitudeControllers = new List<GameObject>();
physicsBody = GetComponent<Rigidbody2D>();
physicsBody.AddTorque(10000);
foreach (Transform child in transform) {
if (child.gameObject.name == "Attitude") {
attitudeControllers.Add(child.gameObject);
}
}
}
示例6: Start
// Use this for initialization
void Start()
{
r2d = GetComponent<Rigidbody2D>();
r2d.AddForce(-Vector2.right.Rotate(Random.Range(-minYAngle, -maxYAngle)) * Random.Range(minImpulse, maxImpulse), ForceMode2D.Impulse);
r2d.AddTorque(Random.Range(minTorque, maxTorque));
startY = transform.position.y;
gravity = true;
if (sprites != null && sprites.Length > 0)
{
GetComponent<SpriteRenderer>().sprite = Random2.RandomArrayElement(sprites);
}
}
示例7: Start
void Start()
{
m_randomOffset = Random.Range(0.0f, 1.0f);
float parenty = transform.parent.localPosition.y;
m_targetY = Random.Range(transform.localPosition.y - 2.0f, transform.localPosition.y);
if(m_targetY + parenty > -2.0f)
{
m_targetY = Random.Range(-10.0f - parenty, -4.0f - parenty);
}
m_rigidbody = GetComponent<Rigidbody2D>();
m_rigidbody.AddForce(new Vector2(Random.Range(-10.0f, 10.0f), Random.Range(1.0f, 10.0f)), ForceMode2D.Impulse);
m_rigidbody.AddTorque(Random.Range(10.0f, 100.0f));
}
示例8: Awake
void Awake()
{
hpScript = GetComponent<HealthScript> ();
sprite = GetComponent<SpriteRenderer> ();
player = GameObject.FindGameObjectWithTag ("Player");
WorldGen = GameObject.Find ("WorldGenerator").GetComponent<WorldGenerator>();
float size = Random.Range (minSize, maxSize);
float torque = Random.Range (minTorque, maxTorque);
float force = Random.Range (minForce, maxForce);
transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
transform.localScale = new Vector3 (size, size, size);
rb = GetComponent<Rigidbody2D> ();
rb.mass = size * 2000;
rb.AddTorque (torque, ForceMode2D.Impulse);
rb.AddForce (transform.up * force, ForceMode2D.Impulse);
hpScript.maxHp = Mathf.RoundToInt(30 * size);
hpScript.hp = Mathf.RoundToInt(hpScript.maxHp - Random.Range (0, hpScript.maxHp));
}
示例9: OnTriggerEnter2D
void OnTriggerEnter2D(Collider2D other) {
//DEAD DEBUG BELOW
if (other.gameObject.tag == "Goal") {
goalHit=true;
GameObject.FindWithTag("Timer").GetComponent<Timer>().Stop();
if(useHelmet){
GameObject.FindWithTag("Helmet").SetActive(false);
}
GetComponent<PinguNoises>().shouldMakeSound = false;
GetComponent<OlafSigh>().dead = true;
GameObject.FindWithTag("JetPackSounds").GetComponent<JetpackSound>().levelDone = true;
}
if (other.gameObject.tag == "Laser" && debug == false) {
//play explosions and 2 sec later restart? feels nice with insta restart. mby sound
Dead();
}
//Activate Physics objects
if (other.gameObject.tag == "PhysicsObject" && other.GetComponent<Rigidbody2D>().isKinematic == true) {
pObjectToActivate = other.GetComponent<Rigidbody2D>();
pObjectToActivate.isKinematic = false;
torqueToAdd = UnityEngine.Random.Range(-7f, 7f);
pObjectToActivate.AddTorque(torqueToAdd, ForceMode2D.Force);
}
if (other.gameObject.tag == "Fuel") {
Fuel += 100;
Destroy (other.gameObject);
print ("FEUL DAMNIT");
if (Fuel > maxFuel)
Fuel = maxFuel;
}
if (other.gameObject.tag == "ZoneHide") {
detectable = false;
print("HIDE");
}/*
else if (other.gameObject.tag == "Bouncer") {
//bounces pingu
Vector2 pos= new Vector2(0,0);
pos.x = Mathf.Abs(rigidbody2D.position.x) - Mathf.Abs(other.transform.position.x);
pos.y = Mathf.Abs(rigidbody2D.position.y) - Mathf.Abs(other.transform.position.y);
if(Mathf.Abs(pos.x)<Mathf.Abs(pos.y)){
print ("ByttY");
print (rigidbody2D.velocity.y);
Vector2 v =rigidbody2D.velocity;
v.y = Mathf.Round(rigidbody2D.velocity.y);
v.y = -v.y;
if(v.y>0 && v.y<7.0f)
v.y=8.3f;
else if(v.y<0 && v.y>-7.0f)
v.y=-8.3f;
rigidbody2D.velocity = v;
print (rigidbody2D.velocity.y);
}
else if(Mathf.Abs(pos.x)>Mathf.Abs(pos.y)){
Vector2 v = rigidbody2D.velocity;
v.x = Mathf.Round(rigidbody2D.velocity.x);
v.x = -v.x;
if(v.x>0 && v.x<7.0f)
v.y=8.3f;
else if(v.x<0 && v.x>-7.0f)
v.y=-8.3f;
rigidbody2D.velocity = v;
print ("ByttX");
}
else{
Vector2 v = rigidbody2D.velocity;
v = -v;
rigidbody2D.velocity = v;
}
}*/
}
示例10: Start
// Use this for initialization
void Start () {
myRigidBody = GetComponent<Rigidbody2D>();
myRigidBody.AddRelativeForce(Vector3.right * projectileSpeed);
myRigidBody.AddTorque(torque);
}
示例11: Start
// Use this for initialization
void Start()
{
incol = false;
invis = false;
mainstate = GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameController> ();
curasteroidstate = GetComponentInParent<AsteroidManager> ();
curRig = GetComponent<Rigidbody2D> ();
// Scaling
// Get main camera component
main = Camera.main;
// Main camera height and width
camheight = main.orthographicSize * 2;
camwidth = camheight * main.aspect;
// Set temp to ship sprite
temp = GetComponent<SpriteRenderer> ().sprite;
// How big bg1 is in world units
unitWidth = temp.textureRect.width / temp.pixelsPerUnit;
//unitHeight = temp.textureRect.height / temp.pixelsPerUnit;
// Asteroid Details
randomscale = Random.Range (7, 12);
speed.x = 0;
speed.y = Random.Range (curasteroidstate.speedmin, curasteroidstate.speedmax);
turnspeed = Random.Range (-4, 4);
// Scale ship according to camera size
transform.localScale = new Vector3 (camwidth / (unitWidth * randomscale), camwidth / (unitWidth * randomscale));
//Asteroid Initial speeds
curRig.velocity = speed;
curRig.AddTorque (turnspeed);
}
示例12: Start
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody2D>();
// Create some states
stateFree = AddState ("Free");
stateCaptured = AddState ("Captured");
stateFlushed = AddState ("Flushed");
StartState.AddTransition (stateFree).AddTransition (stateCaptured).AddTransition (stateFlushed);
// Get a list of all audio sources on children
audioSources = new Dictionary<string, AudioSource> ();
foreach (AudioSource s in GetComponentsInChildren<AudioSource> ()) {
audioSources.Add (s.gameObject.name, s);
}
Transition (stateFree);
// Apply a random velocity to the ball
rb.velocity = new Vector2 (Random.value * 3, Random.value * 3);
rb.AddTorque(Random.Range(1,3));
}
示例13: Start
private void Start()
{
_Rigidbody = GetComponent<Rigidbody2D>();
float magnitude = Random.Range (MinForce, MaxForce);
float x = Random.Range (-1f, 1f);
float y = Random.Range (-1f, 1f);
_Rigidbody.AddForce (magnitude * new Vector2 (x,y));
float torque = Random.Range (MinTorque, MaxTorque);
_Rigidbody.AddTorque (torque);
// TO-DO: complete this class
}