Giter Site home page Giter Site logo

nickk888samp / rtscameracontroller-cinemachine Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 3.0 258.61 MB

A RTS style Camera Controller for Unity 3D's Cinemachine system.

License: GNU General Public License v3.0

C# 100.00%
camera cinemachine rts-game unity3d

rtscameracontroller-cinemachine's Introduction

Unity 3D Real Time Strategy/City Builder Camera Controller for Cinemachine Virtual Camera

This project is a Camera Controller for RTS style games, it'll also fit perfectly into a City Builder! It works by adding the script to a Gameobject and placing references for the Virtual Camera and the Target itself. The script controlls the Target and the Virtual Camera. Use ANY Input System using the Input Provider system.

Features

  • RTS Style Rotation (With Tilt)
  • RTS Style Zoom
  • RTS Style "WASD" Camera Movement
  • RTS Style Mouse "Drag" Camera Movement
  • RTS Style Screen Sides Camera Movement
  • RTS Style Position and Transform Lock-On-Target
  • Up and Down camera offset.
  • Zoom based movement speed.
  • Rotate Camera via keys.
  • Boundary System confines the camera in a specific area.
  • Invert mouse input.
  • Limits and smoothing.
  • Framerate independent, no matter how fast or slow the game runs, it works the same.
  • Timescale independent, you can "pause" the game and still use the controller.
  • An Input Provider System that lets you connect ANY Input System with the controller.
  • Automatic Ground detection allowing Camera to move up and down depending on the ground.
  • Exposed Script as a Singleton to get access to controller from every script.
  • Works exceptionally well with Gamepads when used with the Unity's Input System.
  • Optional UI Controller (Compas, Zoom Slider, Drag Images, Rotate Image)
  • It's smooth, it's lightweight and it just works.

Requirements

  • Cinemachine

Want to use Unity's Input System?

To get the files, unpack RTSCameraController_NewInputSystem.unitypackage that's located in the RTSCameraController directory while in the editor. Use the RTSCameraController_NewInputSystem.prefab instead or just swap the InputProvider_OldInputSystem.cs with InputProvider_NewInputSystem.cs in the RTSCameraController Game Object. Makes sure to install the Input System package from the Package Manager of course.

Create your own input provider script

Just create a new Script and inherit from the IRTSCInputProvider interface and let your code editor automatically populate with all the methods from the IRTSCInputProvider. Return the values (Bool, float or Vector2) to the specific Methods. Place the script alongside the Controller script and that's it. Just make sure there's only one Input Provider placed as a component. You can use the premade Input Providers as a guide.

How To Use

  • Make sure you have installed the "Cinemachine" package from the Package Manager.
  • If any, delete the default Main Camera from the Scene.
  • Place the "RTSCameraController" (located in the "Prefabs" directory) to your Scene.
  • Have Fun!

Default Settings:

WASD or Middle Mouse Button - Camera Movement

Right Mouse Button or Q or E - Rotation

Mouse Scroll Wheel - Zoom-In/Zoom-Out

R or F - Height Change

forthebadge

rtscameracontroller-cinemachine's People

Contributors

iafahim avatar nickk888samp 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

Watchers

 avatar  avatar  avatar  avatar

rtscameracontroller-cinemachine's Issues

Does not work with unscaled time.

If Time.timeScale is changed, the interaction scales too. In particular this means the camera will not work when Time.timeScale is set to zero (the normal way to Pause in Unity).

Fix is to use Time.unscaledDeltaTime throughout, including as additional parameter to Mathf.SmoothDamp(..., float.PositiveInfinity, Time.unscaledDeltaTime).

It could be an option, or it could just honour CinemachineBrain.IgnoreTimeScale.

License?

Please consider adding a license to clarify how this great asset should be used.
Thanks!

How does the the "Target Locked" functionality work?

Hi, great solution,

I have implemented your solution into my game, all is working great, however I do not understand how you "activate" the "Target Locked" functionality:

How do I select the target I want to zoom into?
Does this work with mouse pan?
If I move my pan to left mouse button will this cause any problems?

Many Thanks
Richard

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.