Having problems with getPos on a bullet vehicle

I am a nooby and hope I am not making a fool of myself with my question. I am busy going through the tutorial trying to learn how to design and code 3D games. Each time I read something cool, I will test it either on new code or modify one of your samples. My 5 yr old was getting impatient with me, so I tried to create something quick and dirty. He likes CARS. So I take the bullet vehicle sample and add a surface from the shadow sample. Then I add game pad control. Then I tried to add following camera logic from the Roaming Ralph. But the camera did not move when the car moved. I then added print statements to see where the problem is. The getPos on the yugoNP node always returns (0,0,0). I spent several days going through the manuals and forums to find a solution. Nothing. Any help is greatly appreciated.

What is “yugoNP”? Could you show us some code, perhaps?

More generally, I’d guess that “yugoNP” is attached to some other NodePath, and that its position relative to that NodePath is left unchanged. You see, when “getPos” is called with no further arguments, it returns the position of the NodePath relative to its parent. Thus if “yugoNP” is attached to something, set to be at (0, 0, 0), and that something is then moved around, “yugoNP.getPos()” will nevertheless continue to return (0, 0, 0), I believe.

If you want to get a position relative to another NodePath–e.g. the standard scene-root, “render”–you can pass in that NodePath as a parameter to “getPos”.

Thus, to get the position of “yugoNP” relative to another NodePath, you might call the following:

pos = yugoNP.getPos(someOtherNodePath)

And to get the position of “yugoNP” relative to “render”, specifically, you might call the following:

pos = yugoNP.getPos(render)

Problem is solved with your suggestion.

This is part of the code sample collection that comes with Panda3D.

np = self.worldNP.attachNewNode(BulletRigidBodyNode('Vehicle'))
np.node().addShape(shape, ts)
np.setPos(80, 50, 1)


# Vehicle
self.vehicle = BulletVehicle(self.world, np.node())

self.yugoNP = loader.loadModel('models/yugo/yugo.egg')

Do these items during every Loop

def update(self, task):
dt = globalClock.getDt()

self.world.doPhysics(dt, 10, 0.008)

## Setup camera tracking ################
self.camera.setPos(self.yugoNP.getX(render), self.yugoNP.getY(render) - 20, self.yugoNP.getZ(render) + 16)


return task.cont

Your suggestion DID work. I added “render” to the getPos() to make it getPos(render).
Problem solved. Thanks.

I know I have a long way to go before I have a decent understanding. But hands-on is much better than just reading.

I’m glad that you got it working. :slight_smile:

If I may, I have a “beginner’s tutorial” that may be of interest to you: it takes one through the basics of using the engine, from some of the fundamental concepts, through implementation, and on to building a distributable.

If you’re interested, you should find it here:

Thanks. I am currently in China. That server is blocked. I will bookmark it anyway.

Unless you have an alternative method of getting it to me. Haha

Ah, that’s a pity! Good old China and its censorship. :/

Hum… The assets and image-files for the tutorial are likewise stored on GitHub, so if the main page is restricted, then I’m guessing that the assets are, too. Short of dumping everything into DropBox (and is that restricted…?), I’m not sure of what to do.

GitHub works fine.

Censorship is a royal pain. I am missing out on lots of great content. Can’t wait until it is safe to travel again. Probably not going to happen this year.

Well, if you can access GitHub, then you might be able to access the base repository that hosts the tutorial. (Note that the link that I gave was a Github link–but one specific to GitHub’s document-hosting interface.)

I’m not sure of whether base GitHub will parse the markup for you, or whether you’ll have to either deal with the markup or find a viewer for it.

Here, then, is the base GitHub link:

I was able to download direct from github. Thank you.

1 Like

I’m glad that it worked! Enjoy the tutorial, and I hope that it proves useful! :slight_smile: