public static void GetForceAndTorque(Rigidbody2D body, LineSegment target, out Vector2 force, out float torque)
    {
        Vector2 targetCenterOfMass = target.p1 + (target.p2 - target.p1).normalized * body.centerOfMass.magnitude;

        force  = PhysicsHelper.GetMoveToForce(body, body.worldCenterOfMass, targetCenterOfMass);
        torque = PhysicsHelper.GetRotateToTorque(body, target.Angle());
    }
Beispiel #2
0
    void FixedUpdate()
    {
        LineSegment target = new LineSegment(p1, p2);
        float       centerOfMassDistance = rb.centerOfMass.magnitude;
        Vector2     targetCenterOfMass   = p1 + (p2 - p1).normalized * centerOfMassDistance;
        Vector2     force  = PhysicsHelper.GetMoveToForce(rb, rb.worldCenterOfMass, targetCenterOfMass);
        float       torque = PhysicsHelper.GetRotateToTorque(rb, target.Angle());

        rb.AddForce(force);
        rb.AddTorque(torque);
    }
Beispiel #3
0
 public bool Parallel(LineSegment L2)
 {
     if (this.Angle() == L2.Angle())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
    protected void AddSimpleForces()
    {
        if (DO_DEBUG)
        {
            Debug.Log("Break point");
        }
        if (target == LineSegment.zero)
        {
            return;
        }
        var targetAngle = target.Angle();
        var deltaAngle  = Mathf.DeltaAngle(rb.rotation, targetAngle);

        // Notice that here we are treating torque like acceleration. This is
        // because we want the spring to effect all objects' accereration
        // identically, where it does not depend on their mass. This makes
        // shadow edges reach their targets consistently.

        var accel = PhysicsHelper.GetSpringTorque(0, deltaAngle, rb.angularVelocity, lightSource.GetAngularVelocity(), springConstant, dampingConstant);

        accel = Mathf.Clamp(accel, -maxAccel, maxAccel);

        rb.AddTorque(accel * rb.inertia);
    }
Beispiel #5
0
 private void btnAngle_Click(object sender, EventArgs e)
 {
     txtAngle.Text = ls1.Angle().ToString();
 }
 public static void GetForceAndTorque(Rigidbody2D body, LineSegment actual, LineSegment target, out Vector2 force, out float torque)
 {
     target = target.Rotate(body.rotation - actual.Angle());
     target = target + (body.position + actual.p1);
     GetForceAndTorque(body, target, out force, out torque);
 }