Music timing

Hello everyone again

I try to schedule the sound (a car) by command
“SetVolume”
When I multiply it with the variable “Y”

But I can not get to catch up with the real Y position of my car
It always takes the
getY initial

How can I make it run right?

this is my code:

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
    
    
        
       
        
     
        
        self.front = Actor("car")
        self.front.setScale(7, 7, 7)
        self.front.reparentTo(self.render)
        self.front.setColor(0.6, 0.6, 1.0, 1.0)
        self.front.setPos(-70, 2300,25)
       
        
        
        
        mySound = base.loader.loadSfx("test.ogg")
        mySound.play()
        
        
        def Ps(self):
          mySound.setVolume(self.front.getY*0.5)
         
        
        
        
       
      
       
        imageObject = OnscreenImage(image = 'try.png', pos = (-0.5,0,0.02),parent=render2d)
        base.cam.node().getDisplayRegion(0).setSort(20)
        imageObject.setScale(2,1,1)
        
        pandaPosInterval1 = self.front.posInterval(13,
        Point3(0, -10, 0),startPos=Point3(-70, 2300,25))
        
        
        
       
       
        
        
        
        
        
        pandaHprInterval1 = self.front.hprInterval(3,
        Point3(180, 0, 0),
        startHpr=Point3(0, 0, 0))
        
       
        self.pandaPace = Sequence(pandaPosInterval1,name="pandaPace")
        
        
        
        self.pandaPace.loop()
        
    


        
        
        
        
        
        
        
app = MyApp()
app.run()

like you can see i need to make
Def Ps
looping

You want to make Ps into a task. Try taking a look at the Task section in the manual. Also look at the sample programs, some of them demonstrate the use of tasks. There are also plenty of examples of tasks in the forums.

David

you help me it’s working