My attempt at Hit Detection... is it Efficient?
Posted: Tue Dec 09, 2014 1:06 am
So I've been messing around with love for about a year now and I'm loving it! I use the forums all the time but this is my first post.
Anyway, I was playing around with methods of hit detection, and my current model goes something like this-
Because, if a person is moving at say 100 pixels per frame and their own width is only 20 pixels, then there's an eighty pixel range wherein they can miss detecting something.
So to combat this I've made a box that is a hexagon that stretches from the corner of one to the other taking into account the change in horizontal and vertical velocity. It's probably most simply explained with a picture so here's what it looks like
The red corner is where the person will be next based on their h and v velocity, the green corner is their current location, and the white lines connect the two, as the inside corners are unnecessary.
So I test for contact with any of those lines and if something is inside it. In this case the thing hitting it in question would be a line over the blue thing coming out of the gray character. So I take the line and cycle it through every entity (mobs, breakable objects, the other player) to see if it should do something to it.
My basic question is: is this efficient? Right now with just two entities in play the detection could be super inefficient and I wouldn't know it. Is there some thing that every game dev knows to implement hit detection super easily that would save me the trouble now of learning it later?
I've heard people mention ray hit detection? But I don't know what that is.
Anyway, I was playing around with methods of hit detection, and my current model goes something like this-
Because, if a person is moving at say 100 pixels per frame and their own width is only 20 pixels, then there's an eighty pixel range wherein they can miss detecting something.
So to combat this I've made a box that is a hexagon that stretches from the corner of one to the other taking into account the change in horizontal and vertical velocity. It's probably most simply explained with a picture so here's what it looks like
The red corner is where the person will be next based on their h and v velocity, the green corner is their current location, and the white lines connect the two, as the inside corners are unnecessary.
So I test for contact with any of those lines and if something is inside it. In this case the thing hitting it in question would be a line over the blue thing coming out of the gray character. So I take the line and cycle it through every entity (mobs, breakable objects, the other player) to see if it should do something to it.
My basic question is: is this efficient? Right now with just two entities in play the detection could be super inefficient and I wouldn't know it. Is there some thing that every game dev knows to implement hit detection super easily that would save me the trouble now of learning it later?
I've heard people mention ray hit detection? But I don't know what that is.