Forum rules - please read before posting.

Pointer question, Offset

In android i test the "moving touch drag cursor" but is to slow to play teh game like that.

is better whit the pointer following the finger touch,

my question is if i can ofset the pointer to make it follow the finger but offset, a bit more higher than the finger touch so i can see where is the pointer.

thanks

Comments

  • Yes - you can use a delegate function to override the cursor position.  See this tutorial as well as the "Remapping inputs" section of the new Manual.

    Try this:

    using UnityEngine;
    using System.Collections;
    using AC;

    public class OffsetCursorExample : MonoBehaviour
    {

        public Vector2 touchOffset;


        private void Start ()
        {
            KickStarter.playerInput.InputMousePositionDelegate = CustomMousePosition;
        }
       
       
        private Vector2 CustomMousePosition (bool cursorIsLocked)
        {
            #if UNITY_EDITOR
            Vector2 touchPosition = Input.mousePosition;
            #else
            Vector2 touchPosition = Input.GetTouch (0).position;
            #endif
            return touchPosition + touchOffset;
        }

    }


    Place it in a C# script named OffsetCursorExample and add to a GameObject in your scene.  You can tweak the Touch Offset field in its Inspector to choose the size of the offset.
  • everything perfect thanks, just only one problem that I cant fix it.

    the pointer is offset, in pc using the mouse the click work well where the pointer is, but in android when you tap nothing happens, the taps seam to be without the offset 
  • Apologies - mistakenly the touch-screen input does not rely on this override.

    I shall look into addressing this in the next release, but in the meantime you can hack it by opening PlayerInput.cs, and replacing line 423:

    mousePosition = Input.GetTouch (0).position;

    with:

    Vector2 touchOffset = new Vector2 (10f, 0f);
    mousePosition = Input.GetTouch (0).position + touchOffset;


    And modifiying the "touchOffset" vector values to suit.
  • In v1.58a, a new delegate will be introduced for touch input.  The original example will need changing to:

    public class OffsetCursorExample : MonoBehaviour
    {

        public Vector2 touchOffset;


        private void Start ()
        {
            KickStarter.playerInput.InputTouchPositionDelegate = CustomTouchPosition;
        }
      
      
        private Vector2 CustomTouchPosition ()
        {
            Vector2 touchPosition = Input.GetTouch (0).position;
            return touchPosition + touchOffset;
        }

    }

  • nice, thanks, I still have some problems trying to integrate this change in android.

    but I think that I going to wait for the new update.

    I see that in cursors we can offset the graphic cursor, maybe that offset could be use for the touch too?



  • Yes, that's a good point!
  • hello, 
    I tried to offset the touch in android but don`t work the script with the new version. I still need to change the line 423 in  PlayerInput.cs?

    can you tell me how I need to do this?

    my principal problem is that the player cant see what he is touching because of his own finger in the screen.

  • So long as you're using the latest release, no change to PlayerInput should be necessary and the updated OffsetCursorExample script should be enough.

    What is it about the script that isn't working?  Don't forget to include the "using" lines posted in the first reply.
  • sorry, I try but not work

    the script is the same as you told me. but there no offset in the touch position.

    I added the script in an actor in my scene and there is no error but still nothing happens with the touch position, I tried 


    using UnityEngine;
    using System.Collections;
    using AC;

    public class OffsetCursorExample : MonoBehaviour
    {

        public Vector2 touchOffset;


        private void Start ()
        {
            KickStarter.playerInput.InputMousePositionDelegate = CustomMousePosition;
        }
        
        
        private Vector2 CustomTouchPosition ()
        {
            #if UNITY_EDITOR
            Vector2 touchPosition = Input.mousePosition;
            #else
            Vector2 touchPosition = Input.GetTouch (0).position;
            #endif
            return touchPosition + touchOffset;
        }

    }

  • sorry, I try but not work

    the script is the same as you told me. but there no offset in the touch position.

    I added the script in an actor in my scene and there is no error but still nothing happens with the touch position, I tried 


    using UnityEngine;
    using System.Collections;
    using AC;

    public class OffsetCursorExample : MonoBehaviour
    {

        public Vector2 touchOffset;


        private void Start ()
        {
            KickStarter.playerInput.InputMousePositionDelegate = CustomMousePosition;
        }
        
        
        private Vector2 CustomTouchPosition ()
        {
            #if UNITY_EDITOR
            Vector2 touchPosition = Input.mousePosition;
            #else
            Vector2 touchPosition = Input.GetTouch (0).position;
            #endif
            return touchPosition + touchOffset;
        }

    }

  • That's not the same as the updated script I posted - see that "Mouse" is referenced in your Start function, but the name of the function beneath is "CustomTouchPosition".

    Replace the line inside your Start() function with this:

    KickStarter.playerInput.InputTouchPositionDelegate = CustomTouchPosition;
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.