get nodes closer?

is there an easy short way to get one node closer to another, without changing their angles or parenting them to each other?

None that I’m aware of ‘built-in’,

you could probably throw together your own way of aligning two objects together using NodePath.getBounds() or NodePath.getTightBounds() and then moving one relative to the other’s position etc…

Best of luck,
~powerpup118

node2.setPos(node2.getPos() + (node1.getPos() - node2.getPos()) * 0.5)

Moves your nodes twice as close.

Oh nice.
Do you think this is a good idea for “zooming to mouse position” for the camera, instead of just straight zooming (base.camera.setY(base.camera, value)?

And how can I change their distance with a specific value, like 0.2 units?

Something along the lines of:

vector = node1.getPos() - node2.getPos()
vector.normalize()
node1.setPos(node2.getPos() + vector * 0.2)

Nice.
But if I’ll need to do it each frame, maybe creating a new vector object each frame would be too much.

How about attaching a dummy node to the moving node, telling it to lookAt() the other node each frame and then using that dummy node’s space to move the node (which its attached to)?
I’m guessing it would be a problem trying to move a parent node relative to it’s child node’s space.

I invite you to make some performance measurements to determine whether creating a temporary vector once per frame has a measurable impact on your performance. :wink:

David

I think lookAt creates a lot more under the hood than just a single vector, while lookAt probably still won’t have a measurable impact on the performance.

OK

Wait, won’t multiplying it with 0.2 and adding the current position cause it to move the 0.2th of the current lenght, not 0.2 units?

No, because I normalized the vector to unit length first.

Oh, alright

It doesn’t seem to work.

from panda3d.core import *
import direct.directbase.DirectStart

node1 = loader.loadModel('smiley')
node1.reparentTo(render)
node1.setPos(24,8,17)

node2 = loader.loadModel('panda')
node2.reparentTo(render)

def func():
	vector = node1.getPos() - node2.getPos()
	vector.normalize()
	node1.setPos(node2.getPos() + vector * 0.2)

base.accept('a', func)

run()

Did you mean

node1.setPos(node1, node2.getPos() + vector * 0.2)

maybe?

It seems to work fine for me. It’s given a distance of 0.2 to the origin of the other model.

Oh,
I meant can you move it 0.2 units closer to node2.

Either way, any value doesn’t seem to affect much, it always ends up somwhere at (0,0,0).

I’ll leave that up to you to fix, it’s a rather easy one, you just need to swap node1 and node2 around in a few places.

from panda3d.core import *
import direct.directbase.DirectStart

node1 = loader.loadModel('smiley')
node1.reparentTo(render)
node1.setPos(24,8,17)

node2 = loader.loadModel('panda')
node2.reparentTo(render)

def func():
   vector = node2.getPos() - node1.getPos()
   vector.normalize()
   node1.setPos(node1.getPos() + vector * 0.2)

base.accept('a', func)

run()

:slight_smile: