当前位置: 首页>>代码示例>>C#>>正文


C# Rigidbody2D.AddForceAtPosition方法代码示例

本文整理汇总了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);
		}
	}
开发者ID:JonathanOdgis,项目名称:ProjectAlpacaArduinoTest,代码行数:46,代码来源:ArduinoShootingBehaviour.cs

示例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;
    }
开发者ID:RPITeamTree,项目名称:Spelleo_RGS2015,代码行数:18,代码来源:Iceball.cs

示例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);
	}
开发者ID:james-sullivan,项目名称:StickeyBallGame,代码行数:6,代码来源:AttachScript.cs

示例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;
    }
开发者ID:gorecode,项目名称:they-will-burn,代码行数:23,代码来源:FlyingEnemyLimb.cs

示例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));
                
            }
        }
    }
开发者ID:slehmann1,项目名称:purgatory,代码行数:25,代码来源:explosionForce.cs


注:本文中的UnityEngine.Rigidbody2D.AddForceAtPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。