Hi,
I have found some similar threads in the forum, but none are quite what I need.
I am making a 2D adventure game with no player (1st person perspective) but the player should be able to "look around" the scene in 2D space.
This behavior is almost identical to the GameCamera2DDrag, but I don't want to drag the mouse for the camera to move.
Is there a method to disable moving the camera only on drag?
I saw the isDragControlled property in the GameCamera2DDrag class, will changing this in the script do the trick?
Thank you in advance for the info.
Comments
Duplicate the script, name it e.g. "GameCamera2DLook", and set that as the class name at the top of the script too. It won't have a nice Inspector, but you can do the same for GameCamera2DEditor if you want.
Then, find the _Update function around line 98:
public override void _Update ()
{
if (KickStarter.stateHandler.gameState != GameState.Normal)
{
inputMovement = Vector2.zero;
}
else if (KickStarter.playerInput.GetDragState () == DragState._Camera)
{
inputMovement = KickStarter.playerInput.GetDragVector ();
}
else
{
inputMovement = Vector2.zero;
}
and replace it with:
Vector2 lastMousePosition;
public override void _Update ()
{
if (KickStarter.stateHandler.gameState != GameState.Normal)
{
inputMovement = Vector2.zero;
}
else
{
inputMovement = ((Vector2) Input.mousePosition - lastMousePosition) / Time.deltaTime;
}
lastMousePosition = Input.mousePosition;
Further tweaks can be made if necessary, but that's most of the way. You can then take your existing camera and swap the old script for this one.
I have my own implementation of this kind of camera, but it was before I started using Adventure Creator and I wanted to "plug in" in the Adventure Creator architecture to be more consistent.
But for now I have it working as I want with the code you provided. I just added a custom editor script almost identical to the editor script for the drag camera so I have nice uniform editor UI.
I am so glad I started using Adventure Creator!