Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] Mobile RTS Camera

Discussion in 'Assets and Asset Store' started by chemael, Apr 15, 2016.

  1. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195


    AssetStore Link

    About

    This is a script package for control camera’s position & zoom with mobile touch input for RTS games in Mobile Environment.

    Features
    - Pixel perfect touch camera panning
    - Inertia camera movement
    - Pinch zoom in / out
    - Pinch camera rotation
    - Two finger drag to raise / lower camera x rotation
    - Picking 3d object with event function
    - Long touch town to picking
    - Perspective & Orthographical camera mode support
    - Unity 4.6.x, 5.x support
    - Easy to use. just drag & drop camea prefab to the scene

    Demo & Resources
    - Watch game play video in Youtube
    - Read Documents
    - WebGL Sample
    - Download & Test Android APK
     
  2. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    How to add 'Mobile RTS Camera' to your scene

    - Create new Scene
    - Drag MobileRTSCam prefab to your scene.
    - Remove old Main Camera from the scene.
    - Select MobileRTSCam from Hierachy and Change property at Inspector panel.
    (If your scene don’t have Canvas & EventSystem, add this by selection UI>Canvas in context menu over Hierachy Panel)

    MobileRTSCam gameobject used for camera position & rotation.
    Main Camera gameobject used for zoom only. so, do not set Main Camera’s position and rotation value.
     
  3. VoidFletcher

    VoidFletcher

    Joined:
    Apr 15, 2015
    Posts:
    4
    Hi there!

    Great work. This script runs really nice for what I need it to do, I am however having one issue pertaining to if the object is not on Y = 0, it seems to glitch out. I was wondering if you could drop me a direct message or an email to Support@DeeplinkStudios.com and assist me in adjusting the script so that trSelected stays on the same Y level and doesn't derp out when dragged.

    Much appreciated!
     
  4. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @VoidFletcher
    Hi, Thank you for purchasing my asset.
    To preserve object's y height after draged, change codes below in SceneTest.cs.
    1. Add variable to save Selected Object's initial Y value.
    Code (csharp):
    1.  
    2.     private float      ObjectYStart = 0.0f;
    3.  
    2. Get selected object's y height as a variable when object was selected.
    Code (csharp):
    1.  
    2.     public void SelectObject(Transform trNew) {
    3.  
    4.        // if previous selected object exist
    5.        if((trNew != trSelected) && (trSelected != null)) {
    6.          // set scale to 2.0f
    7.          trSelected.localScale = new Vector3(2.0f,2.0f,2.0f);
    8.          trSelected = null;
    9.        }
    10.          
    11.        trSelected = trNew;
    12.  
    13.        // if newly selected object exist
    14.        if(trSelected != null) {
    15.          // set scale to 2.4f
    16.          trSelected.localScale = new Vector3(2.4f,2.4f,2.4f);
    17.          ObjectYStart = trSelected.position.y;
    18.        }
    19.      }
    20.  
    3. Set object's y position with saved variable while object in dragging.
    Code (csharp):
    1.  
    2.     public void OnDrag(Ray ray) {
    3.        
    4.        if((trSelected != null) && (trPreClicked == trSelected)) {
    5.  
    6.          // change position of selected object
    7.          float enter=0.0f;
    8.          MobileRTSCam.instance.xzPlane.Raycast(ray, out enter);
    9.          Vector3 vPosPick = ray.GetPoint(enter);
    10.          vPosPick.y = ObjectYStart;
    11.          trSelected.localPosition = vPosPick;
    12.        }
    13.      }
    14.  
     
  5. VoidFletcher

    VoidFletcher

    Joined:
    Apr 15, 2015
    Posts:
    4
    Perfect!

    Thanks a ton, chemael. I have one last question, I do apologize if it's a bit obvious (I normally handle the creative side of things, haha!), but how would I go about having certain objects muted, so that your script does not apply to them? Feel free to drop me the code via a convo if that would be better for you.

    Thanks a million, this script is exactly what I needed, I'll drop a review down when I am back at the office.

    Much appreciated!
     
  6. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @VoidFletcher
    I recommend you to use tag name to check which object is selectable or not.
    For example, you can set tag name of selectable object as 'selectable', and 'unselectable' to other objects.
    And in SelectObject function in SceneTest.cs, you can check gameobject's tag name.
     
  7. VoidFletcher

    VoidFletcher

    Joined:
    Apr 15, 2015
    Posts:
    4

    Perfect, thanks a ton! Will be dropping a 5-Star in a sec.
     
  8. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
  9. Kabendji

    Kabendji

    Joined:
    Feb 9, 2013
    Posts:
    24
    To @chemael
    Is this working in Standalone version on a Touch Screen Device on Windows 10?
     
    Last edited: Aug 12, 2016
  10. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @Kabendji
    Hi, Thank you for interesting in my asset.
    Sure, 'Mobile RTS Camera' works well on Windows 10 devices.
     
    Kabendji likes this.
  11. Kabendji

    Kabendji

    Joined:
    Feb 9, 2013
    Posts:
    24
  12. cattagames

    cattagames

    Joined:
    Jul 27, 2016
    Posts:
    8
    Hi @chemael !
    I have a problem with your Mobile RTS Cam script.
    This problem is somehow related to the upgrade i made from Unity 5.3 to 5.4 .
    Everything was working well before.
    Since the upgrade my UI buttons don't receive inputs anymore when i build my game for Android and using Unity remote app, so it has to do with Touch inputs. No problems at all playing the game in the editor with mouse inputs.
    I tried to disable the script component and touch inputs are now working ok for the UI.

    Have you tested the asset on Unity 5.4? Do you have any known issue?
    If you want i can try to make a new project for you to test my problem.

    Thanks
     
  13. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @cattagames
    Hi, Thank you for purcahsing my asset.
    Current version was tested at unity v5.4.3.
    I will test 'Mobile RTS Camera' at unity 5.4.1 and reply to you soon.
     
  14. cattagames

    cattagames

    Joined:
    Jul 27, 2016
    Posts:
    8
    @chemael, i just realized the problem was caused by some minor changes i've made in your script to make it work by my needs.
    Still, i made these changes before updating Unity to 5.4.1 and before that it worked well, so i think something changed Unity-side, not on yours.
    I really apologize for not thinking about that before!
    Great asset!
     
  15. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    HotFix!
    There are some problem in drawing border.
    Please replace OnDrawGizmo function in MobileRTSCam.cs like below.
    Code (csharp):
    1.  
    2. void OnDrawGizmos(){
    3.     Gizmos.color = Color.red;
    4.  
    5.     if(BorderUse) {
    6.         Gizmos.DrawLine(new Vector3(XMin,0,ZMin), new Vector3(XMax,0,ZMin));
    7.         Gizmos.DrawLine(new Vector3(XMin,0,ZMax), new Vector3(XMax,0,ZMax));
    8.         Gizmos.DrawLine(new Vector3(XMin,0,ZMin), new Vector3(XMin,0,ZMax));
    9.         Gizmos.DrawLine(new Vector3(XMax,0,ZMin), new Vector3(XMax,0,ZMax));
    10.     }
    11. }
    12.  
     
  16. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    Hi,

    The 'Mobile RTS Camera' disable GraphicRaycaster of canvas while dragging.
    It was designed to prevent unintended ui event while dragging, but in unity 5.4 and android build, a bug - button click event was not work - was reported.
    So if you want to fix this issue, comment all GraphicRaycaster related code in MobileRTSCam.cs like below.
    Code (csharp):
    1.  
    2. // private GraphicRaycaster gr;
    3. // gr.enabled = false;
    4. // gr.enabled = true;
    5.  
     
  17. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    228
    Just purchased this asset and it's super easy to use. I love it so far.

    Would love a way to turn off (lock) camera rotation on selected axis (x, y, z) as sometimes things get a little outta-whack when playing around with touches on the device.

    Would also really REALLY like to have an Elasticity (bounce) option (like on iOS slider views bounce when you scroll past the end).

    Other than those two wish-list items this is a fantastic asset!
     
  18. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @blamejane
    Thank you for purchasing my asset.
     
  19. eyalchess

    eyalchess

    Joined:
    Feb 18, 2016
    Posts:
    30
    I bought your code, but i don't really succeed to test it on my android device.
    unity remote doesn't work for me.
    What are the alternatives?
     
  20. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @eyalchess
    I have tested my asset on android device. and it works well.
    If you are using unity remote, check unity remote was work normally.
     
  21. Jalechah

    Jalechah

    Joined:
    Mar 12, 2014
    Posts:
    10
    @chemael

    Thank you for this RTS camera. I have something to ask you. In the PDF manual is warns
    "Caution
    In MobileRTSCam, zoom value was setted as z position of Main Camera.
    So, DO NOT modify Transform values of Main Camera object."

    I wish to have the camera follow a unit that moves around while still keeping the functionality of the RTS camera.
    Any suggestions on how to approach this since parenting the camera to the unit will cause the transform to shift around.

    Thanks.
    - James B.
     
  22. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @Jalechah

    Hi,
    Thank you for purchasing my asset.

    You can use SetCameraPosition and SetCameraZoom, SetCameraZoomRatio functions of MobileRTSCam class to change camera's position and zoom.
    You can call SetCameraPostion function to change camera's postion when your unit's postion will change.
     
  23. Jalechah

    Jalechah

    Joined:
    Mar 12, 2014
    Posts:
    10
    @chemael

    Thank you for your reply! the SetCameraPosition function worked great.
    I have another question now. In the demo you can hold and then move objects. What functions need to be called to freeze the camera so that the objects can be moved? I'm interrested in freezing the camera in my game at certain points.
     
  24. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @Jalechah
    You can use codes below.

    // disable camara panning & ineritia
    MobileRTSCam.instance.camPanningUse = false;
    MobileRTSCam.instance.InertiaUse = false;

    You can see OnDragStart function in SceneTest.cs for example.
     
  25. schultzz

    schultzz

    Joined:
    Jan 25, 2014
    Posts:
    11
    this looks really good, just a quick question, is there anyway i can map some of these camera functions to a mouse+button?
    i would like the game to be playable on browsers too and this script functions just the way i want.
     
  26. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @schultzz
    Hi,
    You can use mouse drag to move camera, and mouse wheel to zoom on web or pc platform.
    But, camera rotation with mouse was not implemented.
     
  27. Circlenumber

    Circlenumber

    Joined:
    Aug 5, 2013
    Posts:
    19
    Can i use look like sketchfab.Ex:
     
  28. chemael

    chemael

    Joined:
    Feb 18, 2015
    Posts:
    195
    to @Circlenumber
    Hi,
    Current version was aimed to touch input environment.(although mouse mode supported in editor)
    If you want to control like sketchfab above, you must modify the source code.
     
  29. Slaviksoft

    Slaviksoft

    Joined:
    May 23, 2018
    Posts:
    3
    UseYRotation & UseXRotation fully don't work in false state
     
  30. Slaviksoft

    Slaviksoft

    Joined:
    May 23, 2018
    Posts:
    3
    sorry - doesn't work only in editor mode
     
  31. Slaviksoft

    Slaviksoft

    Joined:
    May 23, 2018
    Posts:
    3
    On physical device Samsung S9 doesn't work event OnTouch
    but works event OnTouchDown.
    If finger not moving there are a small random position changes by 1 or 3 points so script thinks that finger is moving.
    I changed fDragCheckMin to 10 but have many bugs after that.
     
  32. starsk

    starsk

    Joined:
    Jun 1, 2017
    Posts:
    1
    Hello. I am having some problems. I am using your assets with the dozzyUI. but I have the problema that the camera get block on the editor because the canvas. could you tell why it may happened this.

    Thanks
     
unityunity