Gravity NOT working

91 views
Skip to first unread message

Gray Marshall

unread,
Feb 1, 2022, 11:25:35 PM2/1/22
to Python Programming for Autodesk Maya
This is silly, but I can't figure it out...

When I do this (and much more) in the GUI, it works fine.. the ball falls when I hit "Play".
When I try to do the same thing with the code below, it doesn't work.  It looks exactly the same in the Outliner & in the Attribute Editor, but no gravity.  Thoughts?

import maya.cmds as mc

mc.polySphere()
mc.rigidBody()
mc.select(clear=1)
mc.gravity()

Marcus Ottosson

unread,
Feb 2, 2022, 2:25:34 AM2/2/22
to python_in...@googlegroups.com

I put together a Bullet example for you, and then realised you were using the system prior to Bullet being introduced to Maya, so I’ll post both examples for future readers.

So I think you’re doing it right, at least it appears to be designed for use in this way. If so, it isn’t doing what it’s supposed to.

import maya.cmds as mc

mc.polySphere()
mc.rigidBody()
# mc.select(clear=1)
mc.gravity()

Firstly, I expect you’ll need to actually have your object selected, as forces are applied per-rigid. The problem however is that when applying gravity via Python, it generates this extra geoConnector node for some reason. :/

image.png

You can “repair” this manually, and end up with what you get when using the Maya Fields menu, by connecting the missing bits like this.

import maya.cmds as mc

mc.polySphere()
rigid = mc.rigidBody()
_, gravity = mc.gravity()
cmds.connectAttr(gravity + ".outputForce[0]", rigid + ".inputForce[0]")
cmds.connectAttr(rigid + ".fieldData", gravity + ".inputData[0]", force=True)

And finally, here’s the Bullet equivalent, plus a ground plane.

from maya import cmds as mc
from maya.app.mayabullet import RigidBody

cmds.file(new=True, force=True)
mc.polySphere()
cmds.move(0, 5)
_, rigid = RigidBody.CreateRigidBody(True).executeCommandCB()
cmds.setAttr("bulletSolver1.groundPlane", True)
cmds.setAttr(rigid + ".colliderShapeType", 2)  # Sphere

These were tested on Maya 2020.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c63567ec-5594-4076-a3cf-ae87b6a8c9cen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages