# When in range of a node do something [SOLVED]

I am trying to make it so that when the player aka ralph gets with in range of a node aka Miyu it prints a message. at the moment it works but only half of it.

``````radius1 = self.miyu.getPos()
radius2 = self.miyu.getPos() + 1
print self.ralph.getPos()

if ( self.ralph.getPos() >= radius1) and (self.ralph.getPos() <= radius2) ) :
print "Alyssa Lend me your power!"
else:
print "Merciful Intelligential Yggdrasil Unit - Miyu"``````

Please donâ€™t mind the random text â€¦ it works mostly, but if I move right next to the node on one side of the X axes it dosent work ><. hehe Iâ€™m sure that it is something simple, just i cant see it.

This is my first real attept at 3D development.
Thanks for reading. Nyaa

first one thing that doesnt seem to be ok, â€śself.miyu.getPos() + 1â€ť doesnt make sense, you add 1 to a vector3.

to answer your question, there are easier ways to get the distance and check if itâ€™s lower then a radius.

``````if self.miyu.getPos(self.ralph).length() < (radiusRalph + radiusMiyu):
print "whatever" ``````

this getâ€™s ralphâ€™s position relative to miyuâ€™s location (a vector3), calculates the length of this vector and compares it with the radius you want to check with (these are fixed values).

i recommend you looking into vector mathâ€™s a bit. understanding how it works can save you lots of trouble.

ah thank you very much, this has helped me alot. this is a lot simpler than mine lmao ^_^, I was tring to add 1 to all three XYZ, I realise now that I need too read up on vector maths I think.

Thank you very much

Keep in mind that Hypnos way of determining the distance is not 100% right, as it gets the distance in ralphâ€™s coordinate system, so you do not get an absolute distance - it is affected by ralphâ€™s absolute scale.

oh right, forgot about the scale influence.

this should go right all the times (as long as you dont scale render , which you really shoudnt do ):

``````if (self.miyu.getPos(render) - self.ralph.getPos(render)).length() < (radiusRalph + radiusMiyu):
print "whatever" ``````