Springen mithilfe von Trigonometrie

GentleXD

Aktives Mitglied
Hallo,

ich entwickle gerade kleines Spiel wo der Spieler zu der X-Position der Maus springen kann.
Sprache Java, LibGDX. Ich habe das erstmal so gelöst das die Y-Variabel mit einem einfachen Sprung verändert wird und die X-Position mithilfe der Berechnung der Trigonometrie. Nun mein Problem die X-Positon wo der Spieler hinspringt ist immer falsch könntet ihr meinen Code mal checken bitte.

Code:
private void MovementAndCollision(float delta) {

    if (delta > 0.1F) {

        delta = 0.1F;

    }

    this.velocity.y -= this.gravity * delta;

    if (this.velocity.y > this.horspeed * 4.0F) {

        this.velocity.y = (this.horspeed * 4.0F);

    } else if (this.velocity.y < -this.horspeed * 4.0F) {

        this.velocity.y = (-this.horspeed * 4.0F);

    }

    float oldY = this.y;

    this.y += this.velocity.y * delta;
    this.hitbox.update(this.x, this.y);

    if ((this.hitbox.TestCollisions(true)) || ((this.hitbox.TestCollisions(false)) && (this.velocity.y <= 0.0F))) {

        this.y = oldY;
        this.velocity.y = 0.0F;
        this.velocity.x = 0.0F;

    }

    this.hitbox.update(this.x, this.y);

    if ((this.hitbox.TestCollisionsDown()) || (this.hitbox.TestCollisions(false))) {

        this.canJump = true;

    } else {

        this.canJump = false;

    }

    this.x += this.velocity.x * delta;

    this.hitbox.update(this.x, this.y);

}

public void SPACE() {

    if (this.canJump) {

        this.velocity.x = (float) Math.cos(getAngle(new Vector2(x, y), Tools.getAbsolutePos(Tools.getAbsoluteMouse().x, Tools.getAbsoluteMouse().y))) * 1000.0f;
        this.velocity.y = (this.horspeed * 2.4F);
        this.canJump = false;

    }

}

LG Gentle
 
Der Code wäre viel zu groß um ihn hier rein zu posten.
Aber ich habe es gelöst.
Danke trotzdem 😀

Lösung:

Es waren einige rechen Fehler drinnen hat jetzt nichts mehr mit Trigonometrie zu tuen.
 

Neue Themen


Zurück
Oben