本文整理汇总了C#中UnityEngine.Rigidbody2D.AddForceAtPosition方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody2D.AddForceAtPosition方法的具体用法?C# Rigidbody2D.AddForceAtPosition怎么用?C# Rigidbody2D.AddForceAtPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rigidbody2D
的用法示例。
在下文中一共展示了Rigidbody2D.AddForceAtPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
void Update()
{
//Checks for Arduino Serial Communication Port
if(!serial.IsOpen)
{
serial.Open();
}
//Parse the string of two bits into a value to initiate shooting or a faster run.
string data = serial.ReadLine();
int shoot = int.Parse(data.Substring (0, 1));
int fast = int.Parse(data.Substring (1, 1));
if (shoot == 1)
{
isShooting = true;
}
else
{
isShooting = false;
}
if (fast == 1)
{
isRunning = true;
}
else
{
isRunning = false;
}
if (isShooting)
{
rocketIns = Instantiate (rocket, this.transform.position, this.transform.rotation) as Rigidbody2D;
rocketIns.AddForceAtPosition (new Vector2 (2000, 0), this.transform.position);
}
if (isRunning)
{
this.transform.parent.gameObject.GetComponent<Controller2DCustom> ().setSpeed (60);
}
else
{
this.transform.parent.gameObject.GetComponent<Controller2DCustom>().setSpeed(30);
}
}
示例2: Explode
private void Explode(Rigidbody2D target)
{
explosion_obj.Explode();
// push target
if (target != null)
{
Vector2 to_target = target.transform.position - transform.position;
Vector2 force = to_target.normalized * Mathf.Max(0, (3f - to_target.magnitude));
target.AddForceAtPosition(force, transform.position, ForceMode2D.Impulse);
}
// particles
trail.Clear();
trail.enableEmission = false;
exploded = true;
}
示例3: AddForceToRigidGivenVelo
private void AddForceToRigidGivenVelo(Rigidbody2D target, Rigidbody2D fromRigid, ContactPoint2D atPosition){
Vector2 force = new Vector2(0.5f * fromRigid.mass * Mathf.Pow(fromRigid.velocity.x,2f),
0.5f * fromRigid.mass * Mathf.Pow(fromRigid.velocity.y,2f));
target.AddForceAtPosition(force, atPosition.point);
}
示例4: Start
// Use this for initialization
void Start()
{
Vector3 position = transform.position;
if (positionOfImpulse != null) {
position = positionOfImpulse.position;
}
r2d = GetComponent<Rigidbody2D> ();
r2d.AddForceAtPosition (Vector2.up.Rotate (Random.Range (minYAngle, maxYAngle)) * Random.Range (minImpulse, maxImpulse), position, ForceMode2D.Impulse);
minStopAngle = minStopAngle;
maxStopAngle = maxStopAngle;
if (minStopAngle > maxStopAngle) {
float t = minStopAngle;
minStopAngle = maxStopAngle;
maxStopAngle = t;
}
startY = transform.position.y;
}
示例5: addForce
private void addForce(Rigidbody2D rigBody)
{
RaycastHit2D rh = Physics2D.Linecast (transform.position, rigBody.transform.position);
float force = (addForce (rh.distance));
float angle = getAngle(transform.position,rigBody.transform.position);
Vector2 forceVector = new Vector2(-Mathf.Cos(angle),-Mathf.Sin(angle));
forceVector *= force;
Debug.DrawRay (rigBody.transform.position,forceVector.normalized,Color.cyan,5f,false);
rigBody.AddForceAtPosition (forceVector,rh.point);
if(rigBody.GetComponent<Snappable>()){
if (rigBody.GetComponent<Snappable>().snapOnExplode)
{
rigBody.GetComponent<Snappable>().destroy();
}
}
if (rigBody.GetComponent<explosionForce>())
{
explosionForce e = rigBody.GetComponent<explosionForce>();
if (e.explodeWithExplosion)
{
StartCoroutine(exp(e));
}
}
}