I am in process of writing my own laser drawing function and I have ran into a math problem.
Have a look at the following image:
The laser is set to fire at a certain point(the top-left corner of the red guy), which it actually does. The top-left, or the bottom-left(not sure which one) corner of the laser beam is exactly at the target coordinate.
What I want to do is to have the lasers middle point at the target point, not the corner.
Here is my code, I am using the following method to draw the laser:
SpriteBatch.draw(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation)
And here is my code:
float angle = MathStuff.getAngle(srcX, srcY, destX, destY); //Calculate the angle between the source and destination point.
batch.draw(beamImage,
srcX,
srcY,
0,
0,
MathStuff.distance(srcX, srcY, destX, destY),
beamImage.getHeight(),
1,
1,
angle);