2D-Projektil-Flugbahn Vorhersage (unity3d)

(Mit unity3d 4.3 2d, es nutzt die box2d Physik).

Habe ich Probleme mit der Vorhersage der Flugbahn
Ich bin mit:

Vector2 startPos;
float power = 10.0f;
float interval = 1/30.0f; 
GameObject[] ind;


void Start (){
        transform.rigidbody2D.isKinematic = true;
        ind = new GameObject[dots];
        for(int i = 0; i<dots; i++){
            GameObject dot = (GameObject)Instantiate(Dot);
            dot.renderer.enabled = false;
            ind[i] = dot;
        }
    }

void Update (){
        if(shot) return;
        if(Input.GetAxis("Fire1") == 1){
            if(!aiming){
                aiming = true;
                startPos = Input.mousePosition;
                ShowPath();
            }
            else{
                CalculatePath();
            }

        }
        else if(aiming && !shot){
            transform.rigidbody2D.isKinematic =  false; 
            transform.rigidbody2D.AddForce(GetForce(Input.mous  ePosition));        
            shot = true;
            aiming = false;
            HidePath();
        }
}

Vector2 GetForce(Vector3 mouse){
        return (new Vector2(startPos.x, startPos.y)- new Vector2(mouse.x, mouse.y))*power;

}

void CalculatePath(){
        ind[0].transform.position = transform.position; //set frist dot to ball position
        Vector2 vel = GetForce(Input.mousePosition); //get velocity

        for(int i = 1; i < dots; i++){          
            ind[i].renderer.enabled = true; //make them visible
            Vector3 point = PathPoint(transform.position, vel, i); //get position of the dot 
            point.z = -1.0f;
            ind[i].transform.position = point;
        } 
    }

    Vector2 PathPoint(Vector2 startP, Vector2 startVel, int n){
               //Standard formula for trajectory prediction
        float t = interval;
        Vector2 stepVelocity = t*startVel;
        Vector2 StepGravity = t*t*Physics.gravity;

        Vector2 whattoreturn = ((startP + (n * stepVelocity)+(n*n+n)*StepGravity) * 0.5f);

        return whattoreturn;
    }

Verwenden, bekomme ich falsche Flugbahn.
1. Es ist wie die Schwerkraft nicht ziehen Flugbahn nach unten überhaupt, und ja, ich weiß, dass die Schwerkraft ist schwach, weil:

t*t*Physics.gravity = 0.03^2 * vector2(0, -9.8) = vector2(0, -0.00882)

Aber das ist die Formel :S
2. Da die Gravitation gering ist, ist die Geschwindigkeit zu stark.

Hier ist das video:
http://tinypic.com/player.php?v=1z50w3m&s=5

Flugbahn Formel bilden:
http://www.iforce2d.net/b2dtut/projected-trajectory

Was soll ich tun?

Fand ich, dass wenn ich
StepGravity etwas stärker wie (0, -0.1)
und devide startVel von 8
Ich bekomme fast direkt Weg, aber ich möchte das nicht, ich brauche echte Flugbahn Weg.

Benutzer answer.unity3d.com sagte ich soll hier Fragen, da hier eine größere Gruppe von mathematischen Programmierer.

Und ich suchte eine Menge über dieses problem (das, wie ich fand, dass die Formel).

InformationsquelleAutor skakac | 2013-12-01
Schreibe einen Kommentar