# libGDX collision detection / bounding the object

I am trying to implement collision detection so I am drawing a red rectangle to see if it is working. When I put the code below into the update method to check if it is going to work the position is not in the right place. The red rectangle starts from the middle and not at the x and y point? So it draws it wrong.

I also have a getter method so nothing wrong there.

bullet.set(getX(), getY(), getOriginX(), getOriginY());


this is for the render

shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(bullet.getX(), bullet.getY(), bullet.getOriginX(), bullet.getOriginY(), 15, 5, bullet.getRotation());
shapeRenderer.end();


I have tried to do it with a circle but the circle draws in the middle and I want it to be at the tip of the bullet. At the front of the bullet. x, y point.

boundingCircle.set(getX() + getOriginX(), getY() + getOriginY(), 4.0f);

shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
shapeRenderer.end();


I need it to be of the x and y as the bullet is in the middle of the sprite when drawn originally via paint.

• You may have to minus half the width and height of the rectangle from the x and y positions… I'm assuming the "getOriginX()" and "getOriginY()" methods return the width and height for the rectangle… try replacing the "bullet.getX(), bullet.getY()" variables with these "bullet.getX() - (bullet.getOriginX() / 2), bullet.getY() - (bullet.getOriginY() / 2)" – Savlon Jun 9 '14 at 1:34
• thay is not working as originally the bullet was drawn facing LEFT and i used the flip method to flip it to face right. and hence the origin starts from the back – johnny-b Jun 9 '14 at 3:48
• log and compare your image/sprite origin with the origin you‘re drawing in the shapeRenderer – alaslipknot Jun 9 '14 at 10:34

rect.x + (width / 2), rect.y + (height / 2)