Forum Archive

Crude HitTest

eliskan175

http://gist.github.com/cbc554a5aab2350b847d

Experimenting with hitTest function. It's a bit rough, I am still learning, but I thought it could be helpful. The idea is you have two objects with "bounding boxes" and this function tells which direction the object is being struck. Used in this example to push one box with the other.

ATM it only works on box-shaped bounding boxes but that would be easy to change. Let me know what you guys think and how to improve!

It also has a couple side features like the size of the boxes changes dynamically according to the gravity.z .. Just ignore those haha the really interesting part for game design is the hit test.

eliskan175

https://gist.github.com/5eb6c63a8e4ab9998e0d

This is a circle-to-circle based hittest. Used a little nifty math to make it accurate.

Matthew_Murdoch187

This works really nicely - thanks!

eliskan175

Thank you! Another example I have been playing with. In this one I modified the particles example because I wanted to test hitting a large array of objects. At about fifty it results in lag, probably because my coding is subpar..

https://gist.github.com/68959f100b41187fa3d6

Any advice or improvements is always welcome!

eliskan175

Very nice work!

I was thinking about a quad implementation but I didn't know exactly how to do something like that. You demonstrated that wonderfully and pretty much tripled the amount of particles the scene can handle. Good job :)

I'm also quite impressed with how you made the already truncated circle hittest even shorter!

Thank you for the contribution, that's pretty cool stuff and I will definitely learn from this.

yodayoda230

.

yodayoda230

thanks dlivingstone! - very devious ways of speeding up the collision checks! :)

sea56

Very cool.

yodayoda230

I see that, although you limit the number of checks cleverly, you still have to check the distance for some, and you use "if((dxdx)+(dydy)<radii*radii)"

I notice there is a command in the documentation-

Point.distance(other_point)

Return the cartesian distance to a different Point object.

And wondered if you could incorporate that instead? Or if you had tried and found it slower than your method

Sebastian

I've noticed that too, I even use it in my own codes, but it does use the square root function which I believe can make it a bit slower.

yodayoda230

Thanks S