Page 1 of 1

Proximity Detection of an Obejct

Posted: Fri Feb 06, 2015 12:42 pm
by Maltasparks
Hi, i am trying to do prox detection
Example: i have a character that moves and there is a tree within 500 pixels then i use isDown("q") and it uses detection, and the closest tree near will start to be chopped(the character x/y will change and he will move near the tree). The chop class called chop_tree() i have the animation and everything in there, so all i need is to know how to use proxy closest object.
Thanks

Re: Proximity Detection of an Obejct

Posted: Fri Feb 06, 2015 9:20 pm
by Bindie
If I understand you correct I guess you want to know how to detect the closest tree regarding to the player:

I would do a for loop over all trees that are within a special x and y from the player like an area of 20? And then store a length of a vector from the player.x and player.y to the tree.x and tree.y and store that to a local treeDistance, and that every vector after should be compared so if there is any tree closer that vector will be stored. I guess doing it in love.keypressed so that the function runs one time compares where the shortest tree is, starts the animation and chops the tree. Hope it was of some use.

Re: Proximity Detection of an Obejct

Posted: Sat Feb 07, 2015 10:48 pm
by tjohnman
Here is some reading on the subject in case you want to try to go further. Don't be scared by the terminology, it's very simple concepts.
http://buildnewgames.com/broad-phase-co ... detection/