How do I move a camera forward x number of units?

I created a Camera extension called Camera Key, that sets all 3 transform keys and all 3 rotation keys at the current keyframe with one button click, which makes it easy to create camera fly throughs (if there is a built in way to do this already, tell me how please).

It works pretty well, except there are times Omniverse won’t let you scroll forward past a certain point and you can’t select a prop forward in the scene because of windows or walls in the way (without hiding).

def on_click():







  label.text = "6 Keys Set"

ui.Button(“Set Keys”, clicked_fn=on_click)

The first part of the question is how to get the current transform of the Camera object?

The part I don’t know and maybe there is some built in math functions to figure out what forward is, meaning the direction the camera is facing? Then how do you go 3 meters forward, for example?

Thanks for any advice.

Hi @DataJuggler. Sounds cool! I don’t think I’ve seen anything like that and I hope you consider publishing it as a community extensions.

These are good questions.

  1. You can get the prim path for the active viewport’s camera. There’s a snippet here where you will find active_viewport.camera_path: Focus, Zoom or Frame a Prim — Omniverse Kit documentation. Then you can use Usd.Stage.GetPrimAtPath().
  2. The forward direction USD Cameras is -Z. You can just move the camera prim 3 meters in its local -Z.

Let me know if you need any more clarification on any of that.

Thank you. I will publish it to Git Hub once I get a few things working.

Only other questions, is can a button in the UI be an image button, and how do you tell if the button is held down?

I was thinking some buttons like this where left and right are rotate and up and down would be forward and back.


Yup. You can added a filepath to an image for the ui.Button: Button — omni.ui 2.14.11 documentation

Instead of the clicked_fn parameter, you can use mouse_pressed_fn and mouse_released_fn to say when you want to start and stop moving/rotating.

Yes, I found that after I posted. I am trying to figure this out now.


The forward direction is much more complicated than just -z.

Unity has a built in direction .Forward. The rotation the camera is facing has to take into account the current rotations and then some sin math I don’t understand has to be applied.

Trying to figure this out now, just wanted to update this.

I tried using mouse_pressed_fn, thinking I could move the camera forward while the button is held down, then release it when the mouse_released_fn is called, however the while loop hijacked the application and Code crashed, or I had to kill it with Task Manager.

Are there anyways to handle the mouse_pressed_fn and continually move without taking over 100% of the apps resources?

I still haven’t figured out forward, but what I did do was add X+, X-, Y+, Y–, Z+ and Z- buttons and after searching the text of your extensions cache, I figured out a slider to set the amount to move.


Rotation I could not figure out. I found this in one of your docs

q = pose.ExtractRotation().GetQuaternion()

rotationX = q.GetImaginary()[1]
rotationY = q.GetImaginary()[1] 
rotationZ = q.GetImaginary()[2]

And rotation comes out to some number like .0087 for 1 degrees. I thought I found the math to convert it by * 360 / Pi, and that worked up from 1 - 15 degrees than stopped working, so I gave up.

If you prefer I create separate threads for these questions, I can.

How do I get the rotation value in degrees?,

I also could never figure out how to get image_url working to create an image button. I guess I don’t know how to get the images to VS Code, because they show up in the folder.

Just wanted to report my progress, and I have a semi working version, so I will publish the project to Git Hub and maybe some others that know more about this stuff can show me what I need to learn to get ‘Drone’ like controls working.

One more issue I ran into over the weekend before I forget.

I was able to get the active_viewport.camera_path, but whenever I tried to make a call to something like this:


I kept getting an error when I tried to build a string like: ‘/World/Camera.xformOp:translate|x’

Something about can’t combine Path and string. As a C# developer the hardest part of working with Python to me, is the data types are all hidden.


Seems like a string, maybe it is something else?

I published the project to Git Hub.

If anyone can show me what I need to learn to add forward, backward, left, right and image buttons, and how to get the current rotation values in degrees I would appreciate the help.


Nice! For the loop issue, a possible better way to do it is to set a variable to know if the button is currently pressed and in an update loop callback move the camera one step.

Here’s an example of setting a Button image via styles: kit-extension-sample-reticle/ at 0a5de112e6d41f6b137cfd0dc632fd133c32588f · NVIDIA-Omniverse/kit-extension-sample-reticle · GitHub

This shows how to get the local Euler angles for an Xformable: Get the Local Space Transforms for a Prim — Omniverse USD documentation

When you’re ready, you can publish your extension to the Third Party tab in the Extension Manager by adding the omniverse-kit-extension topic on Github and publishing a release. I cover that here: How to Share Your Kit Extension to Github with the Omniverse Code App - YouTube

Thank you for all your help. I will digest this as soon as I can.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.