[Solved] Few questions

Hey, I would like to ask few questions about rotating and importing.

  1. Importing

I have a bunch of .py files (Sound.py, Player.py, etc.) in my game directory. And I import all of them in Main.py file, however if I try to use a function from Sound.py in my Player.py file, I throws an error saying that there’s no such function. Do I have to import Sound.py to Player.py if I want to use functions from that file? Maybe my code isn’t “clean” enough?

  1. Rotating

Let’s say I have a door I can open it by pressing “Use” key. But it rotates around its center, instead of its left (or right) side when it opens. What is the best way to rotate objects around certain position, like real door in this case?

Thanks in advance.

EDIT - Oops, I want to ask another question. How can I get width and height of a model?

Thanks again.

For the python files, you need to import what you need into each separate python file.
So if you want to use some function called “boom” from Sound.py in Player.py, you would have to do this in Player.py:

import Sound
Sound.boom(parameter)

You can also do it this way, which makes the syntax the same as if all the functions are in the same file:

from Sound import *
boom(parameter)

The thing to watch out for with this second method is if you define something in Player.py called “boom” it is going to override the one in Sound.py.
Similar to importing the Panda components, you only need one import statement per thing you are importing and these almost always sit at the very top of the script.

  1. yes, you have to import the files/modules in each file you want to use them directly or you have to use an object each in the main file and pass it to each function.

  2. you cold put the door in a new parent node(path) and move it so that the parent’s center is where it should rotate and thedoor is in the same place as it has been before (you could also call flattenstrong on the parent to “remove” the old node)

Thanks for the replies. That was very helpful.

EDIT - Oops, I want to ask another question. How can I get width and height of a model?

Thanks.

Bump

model.getTightBounds() returns a pair of Vec3’s. You can subtract these two to determine the height, width, and depth.

David

Okay, thanks alot.