Unity uses a left-handed, y-up system, which is different with the common right-handed system in a lot of libraries for robotics.

We provide the functions for converting Unity frame to PyBullet frame in PoseUtils

PoseUtils

PoseUtils converts the position, rotation (euler angle), and scale between Unity and PyBullet.

Example

Run pose_convert.py on Python side:

unity_pos = [0.52, 2.28, 0.75]
unity_qua = [0, 0.258819103, 0, 0.965925813]
unity_euler = [0, 30, 0]
unity_sca = [1., 2., 1.5]

id_simulator = p.connect(p.GUI)
p.setTimeStep(0.02)
pose = PoseUtils()
box = p.createVisualShape(shapeType=p.GEOM_BOX, halfExtents=pose.unity_scale_to_bullet_scale((np.array(unity_sca) / 2).tolist()))
p.createMultiBody(baseVisualShapeIndex=box, basePosition=pose.unity_pos_to_bullet_pos(unity_pos), baseOrientation=pose.unity_qua_to_bullet_qua(unity_qua))

while 1:
    p.stepSimulation(id_simulator)
    time.sleep(0.02)

On Unity, open pose_utils scene. There is a cube with unity_pos , unity_euler , and unity_sca . This python script will convert the pose in unity to pybullet, and render a box with the same properties.

APIs

Function Description
bullet_pos_to_unity_pos Convert bullet position to unity position
unity_pos_to_bullet_pos Convert unity position to bullet position
bullet_qua_to_unity_qua Convert bullet quartenion to unity quaternion
unity_qua_to_bullet_qua Convert unity quaternion to bullet quaternion
bullet_sca_to_unity_sca Convert bullet scale to unity scale
unity_sca_to_bullet_sca Convert unity scale to bullet scale

How to use

from pyrcareworld.utils import PoseUtils
env = RCareWorld()
pose_convert = PoseUtils()
my_unity_pose = pose_convert.bullet_pos_to_unity_pos([0, 0, 1])

<aside> 💡 Coordinate system and rotation can be different in different simulation platforms, and can be confusing but very important. To get a better understanding of Unity’s rotation, check

Unity Quaternion and Rotation Guide for beginners - VionixStudio

</aside>