Gravity not finding my object

Hello! I used a CollisionHandlerGravity for my game. But when I attached the camera to it, it isn’t working. I thought it only doesn’t work with camera, but every model I tried doesn’t get effected.

Code:

base.cTrav = CollisionTraverser()
grav = CollisionHandlerGravity
grav.gravity = 9.81

cNode = CollisionNode("camera")
cNode.addSolid(CollisionRay(0, 0, 0, 0, 0, -1))
cameraC = base.camera.attachNewNode(cameraC)
base.cTrav.addCollider(cameraC, grav)

But I get:
grav couldn’t find render/camera, disabling

(It is not exactly what I get. This is what I remember of the warning. I deleted the test program)

  1. You haven’t created a CollisionHandlerGravity
  2. You haven’t added your object to it

Soory. I meant to type:

grav = CollisonHandlerGravity()

and I added by:

base.cTrav.addCollider(cmaeraC, grav)

EDIT: I said I don’t have the test program, so I typed the code manually.
I don’t get any errors, it is a warning.

You also need to add the object to the handler, not just to the traverser.

How?

if you look at the example at Pusher Example — Panda3D Manual you’ll see that they’ve added pusher.addCollider(frowneyC, frowney, base.drive.node()) at the end, I think you need to do the same, please correct me if I’m wrong.

I tried so and it worked. Thanks @azizalbastaki and @rdb.

What is base.drive.node() exactly?

1 Like

My pleasure :slight_smile:

the documentation explanation of this is:

"If you are using Panda’s drive mode to move the camera around (or some other node), then you also need to tell the pusher about the drive node, by adding it into the pusher.addCollider() call:

fromObject = base.camera.attachNewNode(CollisionNode('colNode'))
fromObject.node().addSolid(CollisionSphere(0, 0, 0, 1))

pusher = CollisionHandlerPusher()
pusher.addCollider(fromObject, base.camera, base.drive.node())

"
I am going to assume that Panda’s drive mode is referring to the default camera control that is, by default, enabled whenever a Panda application is running.

If you aren’t using this then I would actually see what happens if you remove the base.drive.node() parameter. If it still works then that’s great, if it doesn’t then keep it as a parameter.

and once again, correct me if I’m mistaken.

When I tried the pusher example, it worked without the drive.node(). So maybe gravity does too.