libgdx - Detect collision between Actors -


i'm trying implement collision detector between player (actor) , obstacle (actor too), , wonder what's best way perform collision detection between them. see users saying create rectangle object in class , update bounds every frame, don't know if best way perform (i'm trying make this, collision detector method triggers before player touches obstacle).

this i'm trying check:

public boolean touchedwall() {     // loop obstacles     (obstacle obstacle : this.world.getobstacles()) {         // check if player collided wall         if (this.bounds.overlaps(obstacle.getbounds())) {             gdx.app.log(configuration.tag, "collided " + obstacle.getname());                           return true;         }     }        return false; } 

and method triggers (it should trigger when player bounds hit wall):

position method triggers

i figured out! instead of using this.bounds.set(x, y, width, height), using this.bounds.set(x, y, height, width) this:

this.bounds.set(this.getx(), this.gety(), this.getheight(), this.getwidth()); 

sorry mistake.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -