hi
i am trying to get collision dectection working properly but when i do it, the collision area keeps moving. no matter what i tried. there are 2 objects and the objects are moving and i cannot get the area of the collision to follow the enemy/object. i am using the method below to see if the collision will work and it does not follow the enemy properly.
the above is an example of how i am using the sprite extension. the object/enemy is a sprite from libgdx the class is extended by sprite.
below is the render of the shape so i can see if the collision area is working.
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(rect1.getX() + (rect1.getWidth() / 2), rect1.getY() + (rect1.getHeight() / 2) - 2, rect1.getOriginX() - 1, rect1.getOriginY() - 4, 1.0f, 1.0f, rect1.getRotation());
shapeRenderer.rect(rect2.getX() - 10, rect2.getY() - 10, rect2.getWidth() - 10, rect2.getHeight() - 10, rect2.getOriginX(), rect2.getOriginY(), rect2.getRotation());
shapeRenderer.end();
this is in the enemy class collision check
rect.set(getX() + (getWidth() / 2), getY() + (getHeight() / 2) - 2, getOriginX() - 1, getOriginY() - 4);
this is to see if the enemy is colliding
public boolean collides(Ball ball) {
if (getX() < ball.getX()) {
return (Intersector.overlaps(ball.getRect1(), rect));
}
return false;
}