Why use control to calculate distance instead of using geometry?

I am following the jME beginners guide book, and building example tower defense project. At the end of Chapter 3 towers check the distance between the tower and the incoming creeps using the Control attached with the creep.

My question is, why use control to check distance? Why not just use Geometry local translation to calculate the distance.

Right now, I have a getter method to get the arraylist of creep geometry and calculate the distance using getLocalTranslation().

Here is excerpt from the book,

Just based on the excerpt you’ve provided and your questions… the question kind of makes no sense.

“Using a control to check distance” is about WHEN to run things. “Why not just use Geometry local translation to calculate distance” is about HOW to calculate things.

For example, if you go with Geometry to calculate distance… when do you run that code? Where?

…a control maybe?

This line is causing the confusion,

it loops over the ArrayList of creep objects that it gets from the GamePlayAppState object, and uses the creep_geo.getControl(CreepControl.class) method to get access to the CreepControl object. The tower determines whether the distance between itself and each creep is lower than a certain value.

Why access controls attached to creep when we can access the geometry.

For the sentence right after that about collecting the creep controls into a reachable list.

Yes, I am adding the geometries to reachable ArrayList, not the controls. Why should I chose controls over geometry?

I don’t know. I would develop a game at all this way so I have trouble defending any of the notions.

Mixing game objects and view objects in this way feels totally alien so I can’t be asked about grammar at that point. :slight_smile:

I’ve found it. The book is asking to add control instead of the Geometry because later we want to call methods implemented in that custom control class.