Model center position

Hello,

I have really weird problem in panda3d.I want to panda3d , when i press some button
create cannon ball in center position of my ship and in “GameLoop” function change Y coordinate about ship center position.

Short “understandable” version: I want to make my ship to shoot.
(In this code, when I press button.Cannon ball goes is some different way.)

Here is my unsuccessful try:

def fire(self):
   self.shoot=1
   self.cannonball=loader.loadModel("models/cannonball.egg")
   self.cannonball.setScale(.14) 
   self.cannonball.reparentTo(render)
   b=self.myship.getBounds()
   self.c = b.getCenter()
   self.cannonball.setPos(self.c)  



def GameLoop(self,task):
        if self.shoot==1:       
             self.some_speed=self.some_speed+0.5    # Created in __init__, default value 0
             b=self.myship.getBounds()
             c = b.getCenter()
             self.cannonball.setPos(c+Vec3(0,self.some_speed,0))
             self.prevtime = task.time
             return Task.cont

I’m trying to solve this about month :confused: :confused: ! So if you have some tips for me…
ANY HELP WOULD BE APPRECIATED , AND EXAMPLES TOO :slight_smile: !

Sorry for my bad english!

Regards,
Eddie!

You’ll need to make the movements relative, by adding a NodePath as first parameter.
A quick guess of mine looks like this:

self.cannonball.setPos(self.myship, Vec3(0,self.some_speed,0))

Hello,

Thanks for you quick reply :slight_smile:! I have one question about your code snippet.I was replace
your code with my and cannonball is always on the same distance from ship.I was put your
code snippet in GameLoop function.

Regards,
Eddie

It most likely means that some_speed is not large enough to compensate for the scale of self.myship. Multiply it by a larger value when applying it.