Closed SpawnTerminator closed 7 months ago
Hi! Thank you for using my solution.
While i indeed need to improve my documentation skills on GitHub, it's extremely easy to "Lock on" a target or position. Currently there are 2 method variants you can use.
If you want the controller to look to a Vector3 World Position, you can use this method variant: https://github.com/Nickk888SAMP/RTSCameraController-Cinemachine/blob/48e67dbbac372dfb33aa009688201721f5aca4b4/Assets/Nickk888/RTSCameraController/Scripts/RTSCameraTargetController.cs#L514
To lock on a transform the controller will track, eg. a moving target like a unit in a RTS Game, you can use this method variant instead: https://github.com/Nickk888SAMP/RTSCameraController-Cinemachine/blob/48e67dbbac372dfb33aa009688201721f5aca4b4/Assets/Nickk888/RTSCameraController/Scripts/RTSCameraTargetController.cs#L530
The zoomFactor
parameter is the Zoom that'll be applied to the camera to the target.
The hardLock
parameter which is defaulting to false, means if the controller should use smoothing or just apply the position.
There's a example "ObjectSelector.cs" script you can look into: https://github.com/Nickk888SAMP/RTSCameraController-Cinemachine/blob/48e67dbbac372dfb33aa009688201721f5aca4b4/Assets/Nickk888/RTSCameraController/Scripts/Misc/ObjectSelector.cs#L38-L48
The script asks for a reference to the controller which now is kind of deprecated because of the singleton pattern in the controller so you can just write:
RTSCameraController.Instance.LockOnTarget(.....);
Call it once, you don't need to call it in update, the controller will do all for you.
For your second question about the mouse pan: Any movement except rotating/orbiting the target will cancel the "Lock On" feature, just like in most RTS games i used as a reference.
If you have any more question, don't hessitate to ask! :)
Best regards! Kevin
Hi Kevin, thanks for the great response,
Just to clarify, I need to add this (below)to the start function of the main RTSCameraTargetController script.
RTSCameraController.Instance.LockOnTarget(.....);
Then add OjectSelector.cs to the gameobjects I want to be able to target and all should be good?
What if I want to use the left mouse for panning and target selection how would that work?
Again, thanks for your code and help with this, when I finally release my game i’ll make sure I give you credit for the silky smooth movement.
Richard
No no, you don't modify the RTSCameraTargetController
script if you don't want to modify the logic itself.
The RTSCameraController.Instance.LockOnTarget(.....);
you'll need to add it to your custom script, the ObjectSelector
should be a single instance, you DO NOT place it to any of the game objects you want to click on.
Create a script of your own with your own logic or just use a single instance of ObjectSelector
on an empty GameObject, place the reference to the RTSCameraTargetController
in the inspector and make sure to set the tag to Selectable
on the objects you want to select, making sure they have a collider on the Root for the Raycast to detect.
If you want to use the same inputs for both features, there'll be a possibility that you'll click on any selectable objects and there'll be a conflict. Make sure to use the Left Mouse Button only selecting or you'll need to use some extra checks.
If you really need to use the same input for both, you can use a simple workaround and make these private fields public or expose them with a getter.
Then, if the player tries to click on a selectable game object, before it shoots a raycast, check if any of these fields associated with the feature it is conflicting, is false. If by "Panning" you mean "Dragging" it'll be the isDragging
field.
Ok, thanks for another great response. I think I understand now, I shall try to work through it, as you can tell I am pretty new to Unity but managing to sort out most of the issues if i am pointed in the right direction. I think I am at least facing the right way now!! Thank you again for your help.
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