[Python] Object rotation

so I’m trying to write an equation for arrow’s
movement in the 3D space.
so this is what I got with my calculations:

self.origin - is a 3D point representing the arrow's
starting position.

alpha = base.camera.getH() * pi / 180
beta = base.camera.getP() * pi / 180
V0 = 100
velocityX = V0 * cos(alpha) * cos(beta)
velocityY = V0 * cos(alpha) * sin(beta)
velocityZ = V0 * cos(alpha)

self.direction = (velocityX, velocityY, velocityZ)

x = self.origin[0] + self.direction[0]*self.dt
y = self.origin[1] + self.direction[1]*self.dt
z = self.origin[2] + self.direction[2]*self.dt - 4.9*(self.dt**2)

in theory it should work. but it doesn’t, so I need some advices please

In general you should avoid using trigonometry functions in your game. Instead, you should use the scene graph to do this kind of thing.

You could let an arrow start at a position and use lookAt with a normalised vector to turn it into a direction, or you could use setHpr to set the rotation in euler angles.

But if you want it to match the camera’s rotation, then the easiest way to do that is just to apply a CompassEffect.

I am not sure I understand. :
can you give me a small example?

Your math seems reasonable, and I agree that what you’ve written looks like it’s the right idea for working. Since you don’t say in what way it fails, or show any surrounding code, we can’t really give you any better advice than rdb’s, which is basically another way to say “you’re doing it the hard way.”

The point is that there are systems already in Panda that make it unnecessary to calculate low-level trigonometry like this. So if the reason it’s failing is that you’re screwing up the trigonometry, then an easy solution would be to stop doing trigonometry directly, and let Panda do it. There are examples of this sort of thing in the samples, for instance in the solar system example.

Or, if the reason that it’s failing is that you’re screwing up the frame-to-frame movement calculations (which you don’t show here), then an easy solution would be to stop doing that directly, and let Panda do it, for instance with a ProjectileInterval. There are examples of this being used in the forums.


Oh yea. sorry about that.
My problem is that I don’t know how to make my arrow
rotate to direction it’s going…

I tried creating a dummy node and put it always ahead
of the arrow and then use lookAt, but it didn’t work.

so for now all I have is this:

    def shoot(self, task):
        if self.arrow.getZ() <= self.floor.getZ():
            self.flying = 0
            return Task.done

        x = self.arrow_direction[0]*self.dt + self.origin[0]
        y = self.arrow_direction[1]*self.dt + self.origin[1]
        z = self.arrow_direction[2]*self.dt + self.origin[2] -4.9*(self.dt**2)
        self.dt += globalClock.getDt()
        return Task.cont

About going the hard way… well, I guess you are right. Just recently I started using Panda engine so I am not familiar with all the utilities it provides, but I am slowly going through the API and the articles, so it will be fine : )

***** EDIT:
I found my problem. I should have checked that my models are rotated in the right direction before exporting them