Forum rules - please read before posting.

2D first person camera moving with the mouse without dragging

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

  • The GameCamera2DDrag script is independent from the rest of AC - meaning you can duplicated it and make changes to it to suit.

    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.
  • Thank you very much! I'll try this ASAP.

    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.
  • You can still use custom cameras with AC - just attach the "Basic Camera" component to it, and it'll be visible to AC's Actions and Scene Manager.  For more, see the "Custom cameras" chapter of the Manual.
  • Thanks again, I'll try that.

    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!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.