AddRelativeForce() public method

Adds a force to the rigidbody2D relative to its coordinate system.

public AddRelativeForce ( Vector2 relativeForce, [ mode ) : void
relativeForce Vector2 Components of the force in the X and Y axes.
mode [ The method used to apply the specified force.
return void
コード例 #1
0
ファイル: Bullet.cs プロジェクト: EduBeziaco/2Dgame
 // Use this for initialization
 void Start()
 {
     r2d = GetComponent<Rigidbody2D> ();
     if(Movimentacao.left){
         r2d.AddRelativeForce (new Vector2 (-speed, 0));
     }else{
         r2d.AddRelativeForce (new Vector2 (speed, 0));
     }
 }
コード例 #2
0
 static public int AddRelativeForce(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             UnityEngine.Vector2     a1;
             checkType(l, 2, out a1);
             self.AddRelativeForce(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             UnityEngine.Vector2     a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode2D a2;
             checkEnum(l, 3, out a2);
             self.AddRelativeForce(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function AddRelativeForce to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #3
0
 static public int AddRelativeForce(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(UnityEngine.Vector2), typeof(UnityEngine.ForceMode2D)))
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             UnityEngine.Vector2     a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode2D a2;
             checkEnum(l, 3, out a2);
             self.AddRelativeForce(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(UnityEngine.Vector2)))
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             UnityEngine.Vector2     a1;
             checkType(l, 2, out a1);
             self.AddRelativeForce(a1);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #4
0
ファイル: GiraBullet.cs プロジェクト: 9/Swordface2.5D
 void Start()
 {
     //startingPosition = transform.position;
     rb2d = GetComponent<Rigidbody2D>();
     rb2d.AddRelativeForce((Vector2.left * force), ForceMode2D.Impulse);
     //Destroy(gameObject, 15);
 }
コード例 #5
0
    public override void Move(Rigidbody2D movingRB, Rigidbody2D targetRB)
    {
        if (movingRB == null || targetRB == null) { return; }

        if (canDash)
        {
            RotateTowardTarget(movingRB, targetRB);

            //if we're not at max speed, add force
            if (movingRB.velocity.sqrMagnitude < (maxVelocity * maxVelocity * forceMultiplier))
            {
                movingRB.AddRelativeForce(Vector2.right * accelerationForce * forceMultiplier, ForceMode2D.Impulse);
                nextMovementTime = Time.fixedTime + movementDelay;
                isDashing = true;
                canDash = false;

                emitParticles = true;

                if (dashAnimator != null)
                {
                    dashAnimator.SetBool(AnimationParams.IS_CHOMPING, true);
                }
            }
        }
    }
コード例 #6
0
ファイル: BulletLogic.cs プロジェクト: DreamSea/GuiShips
	void InitBullet()
	{
		rb2D = GetComponent<Rigidbody2D>();
		maxSpeed = 250;
		rb2D.AddRelativeForce(direction * maxSpeed);
		currentLife = lifespan;
		damage = 1;
	}
コード例 #7
0
ファイル: MoveForward.cs プロジェクト: ironpencil/critomit
    public override void Move(Rigidbody2D movingRB, Rigidbody2D targetRB)
    {
        if (movingRB == null || targetRB == null) { return; }

        //if we're not at max speed, add force
        if (movingRB.velocity.sqrMagnitude < (maxVelocity * maxVelocity * forceMultiplier))
        {
            movingRB.AddRelativeForce(Vector2.right * accelerationForce * forceMultiplier);
        }
    }
コード例 #8
0
    public override void Move(Rigidbody2D movingRB, Rigidbody2D targetRB)
    {
        if (movingRB == null || targetRB == null) { return; }

        RotateTowardTarget(movingRB, targetRB);

        //if we're not at max speed, add force
        if (movingRB.velocity.sqrMagnitude < (maxVelocity * maxVelocity * forceMultiplier))
        {
            movingRB.AddRelativeForce(Vector2.right * accelerationForce * forceMultiplier);

            int numParticles = UnityEngine.Random.Range((int)minMaxParticles.x, (int)minMaxParticles.y + 1);
            if (numParticles > 0)
            {
                particleSystem.Emit(numParticles);
            }
        }
    }
コード例 #9
0
	// Use this for initialization
	void Start () {
		myRigidBody = GetComponent<Rigidbody2D>();
		myRigidBody.AddRelativeForce(Vector3.right * projectileSpeed);
		myRigidBody.AddTorque(torque);
	}
コード例 #10
0
ファイル: Vehicle.cs プロジェクト: jabza/BusSimulator
    void KillOrthogonalVelocity(Rigidbody2D tyre)
    {
        Vector2 relVel = GetLocalVelocity(tyre);
        relVel.y = 0f;

        tyre.AddRelativeForce(-relVel * tyre.mass, ForceMode2D.Impulse);
    }