Coder Social home page Coder Social logo

goutte / godot-trackball-camera Goto Github PK

View Code? Open in Web Editor NEW
45.0 5.0 3.0 84 KB

A Godot addon that adds a trackball camera node without gimbal lock.

License: MIT License

GDScript 100.00%
godot addon camera trackball quaternions plugin godot-engine gdscript godot-addon godot-addons

godot-trackball-camera's Introduction

Trackball Camera for Godot

MIT Release FeedStarvingDev

A Godot 4.x addon that adds a TrackballCamera node without gimbal lock.

The TrackballCamera responds to input from mouse, keyboard, joystick and touch, in order to rotate around its parent node while facing it.

A version for Godot 3.x is available as well. A version for Godot 2.x is available as well.

Features

  • stays around its parent node, even if the latter moves
  • no gimbal lock (quaternions 🌟)
  • camera inertia for a smoother experience (can be disabled)
  • horizon can be stable or free
  • the parent node does not have to be centered in the camera's view
  • analog camera control with joystick, courtesy of @marcello505 (in #4)
  • a bunch of parameters to configure everything as you want it
  • one-click creation of camera actions (jams!)

Install

The installation is as usual, through the Assets Library. You can also simply copy the files of this project into yours, it should work.

Then, enable the plugin in Scene > Project Settings > Plugins.

Usage

Make the TrackballCamera a child of the Node3D to trackball around. Make sure your camera initially faces said node, and is at a proper distance from it. The initial position of your camera matters. The node does not need to be in the center of the camera's view.

You can also use this camera to look around you if you place it atop its parent node, spatially. It's going to rotate around itself, and that amounts to looking around. You'll probably want to set mouse_invert and keyboard_invert to true in that case.

Todo

  • Test if touch works on android and html5, try SCREEN_DRAG otherwise. (see #6)

Feedback and contributions are welcome!

godot-trackball-camera's People

Contributors

goutte avatar marcello505 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

godot-trackball-camera's Issues

Is there a way to make it match the mouse movement exactly and not do the acceleration-deceleration thing ? Like Blender/3DS Max/Maya/Lightwave ?

Is there a way to make it match the mouse movement exactly and not do the acceleration-deceleration thing ? Like Blender/3DS Max/Maya/Lightwave ?

Its current implementation give me motion sickness, when I let go of the mouse I would like it to stop immediately, and when I start the rotation, may I request that it doesn't "pick up speed" but get straight to the actual speed of the mouse like a normal 3D modeling program ? Thanks :D

Zoom in and out function is not working

Hi, I found your trackball camera, and I love it since it fits my need for what I want to use it for. However no matter how much I tried I cannot make the zoom function work. It completely freezes the engine. It might be my fault, if I missed something please point me to the right direction.
Thanks in advance.
Imre

Feature Request: Lock Vertical

Hi Goutte, thanks for making this add-on!

Is it possible to configure the add-on in order to keep the horizon horizontal?

Use `load` instead of `preload` in `plugin.gd`

We'd lose a little (very little) performance during the initial loading of the plugin (not a bottleneck), but it works better with git, since usually the .import/ dir is ignored in projects and fresh clones hiccup on the preload if the .import/ dir is missing, and end up disabling the plugin. Works fine with load as far as I've seen.

This is a hotfix, and perhaps should be handled upstream in Godot, if possible…
But it's cheap, and I'm really not comfortable adding the whole .import/ dir to the versioning control system.

Infinite loop when inertia is disabled and pitch limits are enabled

I only have half the fix for this, for now. (in apply_updown_constraints)

I can envision a more robust solution but it won't work when the rotation axis changes.
I believe it can be done, though. I still need to think some more about this.

I don't like the current implementation of pitch and zoom limits, anyway.
I feel like there's something simple I'm overlooking. Contribs welcome !

Discussion: transition smoothly to another parent node

There are multiple strategies to achieve that.

Some notes

  • rewrite stuff to trackball around a target node instead of the parent, like some other cameras do
  • right now the transform of the parent is applied, it may well be a feature for some of us
  • remove_child, add_child and smooth camera constraint solver ?
  • probably best to use another class if the changes are expensive, or can't easily be toggled on/off

Update for Godot 4

We'll branch the current main into 3.x, and move the master/main to Godot 4, someday soon.

Type everything

Godot will soon use these types to Make Things Run Faster ©.

Conform API casing

Just use snake_case.

Actual camelCase stems from an earlier-than-plugin velleity of avoiding conflict with Godot's internals.

Consortium: installation of camera actions

I know how to automatically add actions upon plugin activation.
But what happens when we disable the plugin ?

Do we remove the actions, or leave them alone ? Should we even use plugin activation to add the actions, or try to add a button somewhere ?

Meta-configuring the behavior of plugin activation/deactivation is … not there yet, afaik.
There's things we can do on our end, but meta plugin config belongs upstream in Godot.

So we have to choose sane defaults.

Feature: automatically add camera actions to project settings
As a game dev
In order to setup the camera faster
I want the camera actions to be created automatically

Scenario: [A] Enabling the trackball camera plugin
Given there should not be an action named "cam_zoom_in"
And the trackball camera plugin should be disabled
When I enable the trackball camera plugin
Then there should be an action named "cam_zoom_in"

# Plugin (de)activation hook hurdle: clean up, or not ?
When I disable the trackball camera plugin
Then there should still be an action named "cam_zoom_in"



Scenario: [B] Pressing a button
Given there should not be an action named "cam_zoom_in"
When I press a button
Then there should be an action named "cam_zoom_in"
# and another button to remove actions

Well I wanted to vote about how to handle the removal in Scenario A, and it's still open, but I like Scenario B better altogether and I just thought of a way to perhaps have it so it's time for me to open up Godot and save this as draft.

action_strength less than or equal to 0.1

Setting action_strength to 0.1 makes keyboard rotation flaky and setting it below 0.1 prevents keyboard rotation. This is problematic because 0.1 is a reasonable value here.

Perhaps either the _epsilon variable should be exported, there should be a warning if action_strength is less than or equal to 0.1, or epsilon should be decreased.

Refactor as Behavior

Refactor most of the trackball logic to add it to a Node whose purpose is to be added as direct child of any Camera3D (or any Node3D for that matter).

This addon should still provide a "battery included" TrackballCamera3D but should also provide a TrackballBehavior (a simple Node, as aforementioned).

Problem with zoom actions

Hi,
page_up and page_down actions cause the same behavior: an uncontrolled zoom out, without the possibility of restoring the original view.
Any suggestions?
Thanks in advance.
-j

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.