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 :slight_smile: it prints a message. at the moment it works but only half of it.

radius1 = self.miyu.getPos()
radius2 = self.miyu.getPos() + 1	
print [radius1, "-", radius2]
print self.ralph.getPos()

if ( self.ralph.getPos() >= radius1) and (self.ralph.getPos() <= radius2) ) :
    print "Alyssa Lend me your power!"
    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 :slight_smile:

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 :slight_smile:

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 :wink:, which you really shoudnt do ):

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