NooB-ish Physics Question

I copy/pasted the Gravity Example code from the manual into something like this:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import *
from direct.gui.OnscreenText import *
from direct.actor.Actor import *
from direct.task.Task import *
import sys,os,math


class World(DirectObject):
    
    def __init__(self):
        base.enableParticles()
        base.disableMouse()
        base.camera.setPos(0,-10,0)
        
        self.Node = NodePath(PandaNode("PhysiksNode"))
        self.Node.reparentTo(render)
        
        self.jetpackGuy=loader.loadModel("Sphere")
        self.jetpackGuy.setPos(0,20,30)
        self.jetpackGuy.reparentTo(render)
        
        self.an=ActorNode("jetpack-guy-physics") 
        self.anp=self.Node.attachNewNode(self.an) 
        base.physicsMgr.attachPhysicalNode(self.an)
        
        self.jetpackGuy.reparentTo(self.anp)


        self.gravityFN=ForceNode('world-forces')
        self.gravityFNP=render.attachNewNode(self.gravityFN)
        self.gravityForce=LinearVectorForce(0,0,-9.8) #gravity acceleration
        self.gravityFN.addForce(self.gravityForce)

        base.physicsMgr.addLinearForce(self.gravityForce)
        

w=World()

run()

The problem is that absolutley nothing is happening… the model isn’t attracted downwards at all… What is wrong with my code?

THX

I think you need to parent jetpackGuy to anp, instead of the other way around. Physics moves an. Anything parented to anp will move with it.

I’m afraid what you said was kinda ambigous for me… could you please be more specific! Thanks, I really apreciate your help!

PS: sorry 4 being so slow…

PPS: Does anyone have a working Physics example? THX!!!

You might want to work yourself trough with some more basic panda stuff, if you don’t know what Laurens meant with reparenting the jetpackguy…

In your current code, self.an is parented to self.jetpackGuy
You apply the physics only to self.an…
self.an is a child to self.jetpackGuy.
If a parent is moved or manipulated in some way, all its children are manipulated in the same way. If a child is manipulated in some way, the parent won’t be affected.

So in your example the physics engine will move self.an around, which is a child to self.jetpackGuy, hence your self.jetpackGuy actor won’t move anywhere.

THANK YOU BOTH!!!
Now I understand how the whole thing works.
I also replaced the script with a working one!