Ejemplo n.º 1
0
    static void NewtonUpdate(NBodyObject body)
    {
        acceleration = Vector2.zero;

        foreach(NBodyObject otherBody in bodies) {

            if(body == otherBody) continue;
            direction = (otherBody._transform.position - body._transform.position);
            acceleration += self.g * (direction.normalized * otherBody.simMass) / direction.sqrMagnitude;
        }

        body.velocity += acceleration * fixedDeltaTime;
        Vector2 position = body.transform.position;
        body.transform.position = position + (body.velocity * fixedDeltaTime);
    }
Ejemplo n.º 2
0
    static void NewtonUpdate(NBodyObject body)
    {
        acceleration = Vector2.zero;

        foreach (NBodyObject otherBody in bodies)
        {
            if (body == otherBody)
            {
                continue;
            }
            direction     = (otherBody._transform.position - body._transform.position);
            acceleration += self.g * (direction.normalized * otherBody.simMass) / direction.sqrMagnitude;
        }

        body.velocity += acceleration * fixedDeltaTime;
        Vector2 position = body.transform.position;

        body.transform.position = position + (body.velocity * fixedDeltaTime);
    }