コード例 #1
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (orbitAround != null)
     {
         rB.velocity += (MyUniverse.CalculateGravity(orbitAround.transform.position, orbitAround.mass, rB.transform.position, rB.mass, orbitAround.GetComponent <Planet>().gravityMult)) * Time.deltaTime;
     }
 }
コード例 #2
0
    void DrawOrbit()
    {
        // init fake bodies
        FakeBody firstObject = new FakeBody();

        firstObject.fakeBody(newObject);
        Vector3[] drawPoints = new Vector3[stepNum];

        //simulate
        for (int step = 0; step < stepNum; step++)
        {
            firstObject.velocity += MyUniverse.CalculateGravity(planet.transform.position, planet.mass, firstObject.position, firstObject.mass, planet.gravityScale);
            Vector2 newPos = firstObject.position + firstObject.velocity;
            firstObject.position = newPos;
            drawPoints[step]     = newPos;
        }
        //lineRend.positionCount = drawPoints.Length;

        // draw orbit
        for (int i = 0; i < drawPoints.Length - 1; i++)
        {
            Debug.DrawLine(drawPoints[i], drawPoints[i + 1], Color.red);

            //lineRend.SetPosition(i, drawPoints[i]);
        }
    }