Proximity Detection of an Obejct

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Maltasparks
Prole
Posts: 2
Joined: Fri Feb 06, 2015 12:38 pm

Proximity Detection of an Obejct

Post 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
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Re: Proximity Detection of an Obejct

Post 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.
User avatar
tjohnman
Prole
Posts: 16
Joined: Sat Aug 04, 2012 8:40 am

Re: Proximity Detection of an Obejct

Post 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/
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 223 guests