I'm implementing circular collision in my game made in Go using a simple rendering framework called Pixel.
The collision works fine with shapes like a drawn circle
But when I try to use it with an image instead of a rendered shape, it thinks it collides slightly before it reaches the image. The larger the image, the larger the error.
Here is where it collides on the images:
The collision is done like so:
[s being the solar panel, seen in the "smaller image", and p being the player.]
math.Pow(math.Pow(s.center.X-p.center.X, 2)+math.Pow(s.center.Y-p.center.Y, 2), 0.5) <= s.size.X
The size.X and size.Y of each image is the same since it's a circle
The centers are calculated correctly and this exact line works with shapes [you can see the yellow outline in the first image, that's the shape it works with.]
Am I doing something wrong? Why would there be an error caused by this when the calculation has nothing to do with the image itself?
Here's how the images are rendered, I assume the problem lies with that somehow:
[g being the generator, seen in the 'Larger image'
func (g Generator) render(win *pixelgl.Window, imd *imdraw.IMDraw) {
mat := pixel.IM.
Moved(g.center)
g.sprite.Draw(win, mat)
}
The shape is drawn based on it's center as well.