Skip to content

Camera Controls [sweet_camera.gd]

Editor-like camera control. It allows user to draw around, around, zoom in/out, and fully interact with PhysicsBodies in 3d. It is made for debugging and messing around with physics. It has:

  • pivot point (half transparent sphere), the camera always rotates around it.
  • cursor (red sphere), the cursor appears when you interact with collision shape.

Current features:

  • RMB (right mouse button) to rotate around pivot
  • Middle mouse button to drag camera around
  • LMB (left mouse button) to "pick-up" any object and "throw" it.
  • Scroll Wheel up/down to zoom in/out
  • TAB to toggle camera controls, when turned off, pivot and cursor will be hidden.

Script options:

  • Camera Mode (tab_switch,always_active,always_deactive)
  • Start Camera Pivot - The position that camera will look at (its pivot point) by default at the start of the scene.
  • Start Camera Rotation - The rotation that camera will be rotated around pivot (degrees) by default at the start of the scene.
  • Start Camera Distance - The zoom/distance camera will be from pivot

  • Do Draging - activates/disables user to drag camera around

  • Do Rotating - activates/disables user to rotate camera around
  • Do Zooming - activates/disables user zoom in and zoom out
  • Do Grabing - activates/disables "pick-up" and "throw" mechanic

  • Show Elements - If true, will show the pivot points and red cursor

  • Use Warning - If true, it will warn you if you accidentally drag on invisible object.

This script is not dependant on other objects, they don't need to have any scripts attached. Only camera needs to have this script. The only requirement is that object had to be RigidBody3D... makes sense, you can not move StaticBody.

Warning

If you have invisible/hidden objects with collision on the scene, you will see the red cursor colliding with them! I know, it is easy to forget about invisible/hidden objects on the scene, so if you ever accidentally click on invisible object, you will get a warning in the console. If you don't want this behaviour, you can disable "use_warning" in the camera options.

Code from my repo: sweet_camera.gd