Panda3d physic cube collision with place

Hello, i don’t understand in the doc how to make an object fall on my flat surface.

i create my surface with CollisionPlane i load my cube object, but the object falls to infinity (not colide with my plane)

import sys

from direct.showbase.ShowBase import ShowBase
from panda3d.core import *

from panda3d.core import AmbientLight
from panda3d.core import DirectionalLight
from panda3d.core import Vec3
from panda3d.core import Vec4
from panda3d.core import Point3
from panda3d.core import TransformState
from panda3d.core import BitMask32
from panda3d.physics import ForceNode, LinearVectorForce
import copy
from panda3d.physics import *

class Physic(ShowBase):

  def __init__(self):
    # enable physics
    base.cTrav = CollisionTraverser("base collision traverser")

    # setup default gravity
    gravityFN = ForceNode("world-forces")
    gravityFNP = render.attachNewNode(gravityFN)
    gravityForce = LinearVectorForce(0, 0, -9.81)  # gravity acceleration

    # Ground Plane
    plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, -4)))
    self.ground = render.attachNewNode(CollisionNode("Ground"))

    model = loader.loadModel('sphere.bam')
    model.setPos(-0.5, -0.5, 10)
    node = NodePath("PhysicsNode")
    an = ActorNode("sphere")
    anp = node.attachNewNode(an)

app = Physic()

You will need a collision handler to actually detect and handle the collision. You do not need a physics system to accomplish what you are trying, but if you do use the built-in physics system, I believe you would need a PhysicsCollisionHandler.

it doesn’t work, I can’t find what I’m looking for in the panda doc or in the forum messages.
I managed to make a simpler code but there is still no colision

import direct.directbase.DirectStart
import random

from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *

loadPrcFileData("", """syn-video 0"""), -30, 10),0,4))

base.cTrav = CollisionTraverser()

collisionHandler = PhysicsCollisionHandler()

collisionPlane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0,0,0)))
plane = base.render.attachNewNode(CollisionNode('planecnode'))

globalForcesForceNode = ForceNode('world-forces')
globalForces = base.render.attachNewNode(globalForcesForceNode)

globalForcesGravity = LinearVectorForce(0, 0, -9.81)


def phyball_dispenser(modelname, scale=1.):
  ball = NodePath(PandaNode('phisicsball'))
  ballActor = ActorNode('ballactornode')
  ballActorNP = ball.attachNewNode(ballActor)
  ballModel = loader.loadModel(modelname)
  ballModel.setPos(0, 0, 10)

  ballCollider = ballActorNP.attachNewNode(CollisionNode('ballcnode'))
  ballCollider.node().addSolid(CollisionSphere(0, 0, 0, 1*scale))


  collisionHandler.addCollider(ballCollider, ballActorNP)
  base.cTrav.addCollider(ballCollider, collisionHandler)
  return ball
smiley = phyball_dispenser('smiley')


I think I used the PhysicsCollisionHandler well, the code doesn’t crash and I give it the right arguments

my goal is to make the smiley face fall on the plane surface.
using panda’s integrated physics engine

Do this and the problem will become apparent:

You’ve put the ball model at a Z of 10 in relation to the physics node. So the ball model hovers over the actual physics shape. You need to call ballActorNP.setPos to position the ball, instead of ballModel. Then you’ll see that the code works.

thank you I understand, you have to put 0,0,0 in position