Announcement

Collapse
No announcement yet.

[SOLVED] Actor Touch Input Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Actor Touch Input Problem

    Hello,

    For a Project of mine, i need a Mobile Input System, that activates an Event, when an Actor is touched (MOBILE Input).
    I found this on the UDN: http://udn.epicgames.com/Three/Mobil...Touch%20Events and it'S exactly what i need.

    When i use that Code though i get two Errors.
    One: Error, 'HandleInputTouch' mismatch delegate 'OnTouch'
    and
    Two: Error, Bad or missing expression in Call 'OnTouch', parameter 1

    I searched the Forum fisrt befor posting and found this Thread: http://forums.epicgames.com/threads/...ndleInputTouch

    But i did not really understand who they solved the problem.

    My CODE:
    MobilePawn
    Code:
    class AthypoMobilePawn extends MobilePlaceablePawn implements(ITouchable);
    
    function OnTouch(ETouchType Type, float X, float Y)
    {
      WorldInfo.Game.Broadcast(self, "Touched:"@self);
    }
    PlayerController:
    Code:
    class AthypoPlayerController extends GamePlayerController;
    
    /** Holds the dimensions of the device's screen */
    var vector2D ViewportSize;
    
    /** If TRUE, a new touch was detected (must be the only touch active) */
    var bool bPendingTouch;
    
    /** Holds the handle of the most recent touch */
    var int PendingTouchHandle;
    
    /** Holds the Actor that was selected */
    var Actor SelectedActor;
    
    /** Maximum distance an Actor can be to be picked */
    var float PickDistance;
    
    /** Maximum amount the mouse can move between touch and untouch to be considered a 'click' */
    var float ClickTolerance;
    
    /** Cache a reference to the MobilePlayerInput */
    var MobilePlayerInput MPI;
    
    /** find actor under touch location
    *   
    *   @PickLocation - Screen coordinates of touch 
    */
    function Actor PickActor(Vector2D PickLocation)
    {
      local Vector TouchOrigin, TouchDir;
      local Vector HitLocation, HitNormal;
      local Actor PickedActor;
       
      //Transform absolute screen coordinates to relative coordinates
      PickLocation.X = PickLocation.X / ViewportSize.X;
      PickLocation.Y = PickLocation.Y / ViewportSize.Y;
       
      //Transform to world coordinates to get pick ray
      LocalPlayer(Player).Deproject(PickLocation, TouchOrigin, TouchDir);
    
      //Perform trace to find touched actor
      PickedActor = Trace(HitLocation, HitNormal, TouchOrigin + (TouchDir * PickDistance), TouchOrigin, true);
       
      //Casting to ITouchable determines if the touched actor can indeed be touched
      if(Itouchable(PickedActor) != none)
      {
        //Call the OnTouch() function on the touched actor
        Itouchable(PickedActor).OnTouch(ZoneEvent_Touch, PickLocation.X, PickLocation.Y);
      }
    
      //Return the touched actor for good measure
      return PickedActor;
    }
    function HandleInputTouch(int Handle, ETouchType Type, Vector2D TouchLocation, float DeviceTimestamp)
    {
      local Actor PickedActor;
      local int i;
       
      //New touch event
      if(Type == Touch_Began)
      {
        //Specify a new touch has occurred
        PendingTouchHandle = Handle;
        bPendingTouch = true;      
      }
      //Touch in progress
      else if(Type == Touch_Moved)
      {   
        for(i=0; i<MPI.NumTouchDataEntries; i++)
        {
          //Test distance touch has moved and cancel touch if moved too far; update touch location if not
          if(MPI.Touches[i].Handle == PendingTouchHandle && MPI.Touches[i].TotalMoveDistance > ClickTolerance)
          {
            bPendingTouch = false;
          }
        }
      }
      //End of touch
      else if(Type == Touch_Ended)
      {
        //Check if a touch is active
        if(Handle == PendingTouchHandle && bPendingTouch)
        {
          //Get actor under touch
          PickedActor = PickActor(TouchLocation);
             
          //Check if actor is touchable and set it as selected; clear current selected if not
          if(ITouchable(PickedActor) != none)
          {
            SelectedActor = PickedActor;
          }
          else
          {
            SelectedActor = none;
          }
             
          //cancel active touch
          bPendingTouch = false;
        }
          
        WorldInfo.Game.Broadcast(self, "SelectedActor:"@SelectedActor);
      }
    }
    event InitInputSystem()
    {
      Super.InitInputSystem();
    
      //Get a reference to the local MobilePlayerInput
      MPI = MobilePlayerInput(PlayerInput);
       
      //Accessing the input handler function to the delegate
      MPI.OnInputTouch = HandleInputTouch;
    
      //get the screen dimensions (used to transform to relative screen coords for the DeProject)
      LocalPlayer(Player).ViewportClient.GetViewportSize(ViewportSize);
    }
    
    defaultproperties
    {
    PickDistance=10000
    ClickTolerance=5
    InputClass=class'GameFramework.MobilePlayerInput'
    }
    and Itouchable.uc
    Code:
    Interface ITouchable;
    
    function OnTouch(ETouchType Type, float X, float Y);
    Can someone help?

    Thanks alot!

    #2
    Bump

    Is it that the Paramteres of OnTouch and HandleInputTouch are not the same maybe?

    Comment


      #3
      It's been a while, but I remember a lot of the UDN's code had to be updated with new parameters. Here's the updated code: http://forums.epicgames.com/threads/...1#post30906912

      Comment


        #4
        Thank you bwhit!
        I'll try it out!

        ------EDIT-----
        Compiles without an Error!
        Just one mistake in the Code here:
        Code:
        var bool                bPendingTouch
        Missing a Semicolon, but otherwise perfect!

        Comment


          #5
          Fixed it. Here's the updated picking example code:

          Code:
          Interface ITouchable;
          
          function OnTouch(ETouchType Type, float X, float Y); //Stub for the classes that implement ITouchable.
          Code:
          class MyPawn extends Pawn implements(ITouchable);
          
          function OnTouch(ETouchType Type, float X, float Y); //Stubbed, as I didn't need anything else to get get the information I needed on tap.
          
          defaultproperties
          {
          }
          Code:
          class MyController extends GamePlayerController;
          
          var int                 PendingTouchHandle;
          var float               PickDistance,ClickTolerance,PreDist;
          
          var vector2D            ViewportSize;
          var bool                bPendingTouch;
          
          var Actor               SelectedActor;
          var MobilePlayerInput   MPI;
          
          event InitInputSystem()
          {
              Super.InitInputSystem();
          
              LocalPlayer(Player).ViewportClient.GetViewportSize(ViewportSize); //don't forget this
               
              MPI = MobilePlayerInput(PlayerInput);
              MPI.OnInputTouch = HandleInputTouch;
          }
          
          function HandleInputTouch(int Handle, ETouchType Type, Vector2D TouchLocation, float DeviceTimestamp, int TouchpadIndex)
          {      
              local Actor PickedActor;
              local int i;
             
              //New touch event
              if(Type == Touch_Began)
              {      
                  //Specify a new touch has occurred
                  PendingTouchHandle = Handle;
                  bPendingTouch = true;      
              }
          
              //Touch in progress
             else if(Type == Touch_Moved)
             {   
                  for(i=0; i<MPI.NumTouchDataEntries; i++)
                  {
                      //Test distance touch has moved and cancel touch if moved too far; update touch location if not
                      if(MPI.Touches[i].Handle == PendingTouchHandle && MPI.Touches[i].TotalMoveDistance > ClickTolerance)
                      {
                           bPendingTouch = false;
                      }
          
                  }
          
             }
          
            //End of touch
             else if(Type == Touch_Ended)
             {
                  //Check if a touch is active
                  if(Handle == PendingTouchHandle && bPendingTouch)
                  {
                       //Get actor under touch
                       PickedActor = PickActor(TouchLocation);
                   
                      //Check if actor is touchable and set it as selected; clear current selected if not
                      if(ITouchable(PickedActor) != none)
                      {
                           SelectedActor = PickedActor;
                      }
                  }
                  bPendingTouch = false;
                  `Log("SelectedActor:"@SelectedActor);
              }
          
          }
          function Actor PickActor(Vector2D PickLocation)
          {
              local Vector TouchOrigin, TouchDir;
              local Vector HitLocation, HitNormal;
              local Actor PickedActor;
             
              //Transform absolute screen coordinates to relative coordinates
              PickLocation.X = PickLocation.X / ViewportSize.X;
              PickLocation.Y = PickLocation.Y / ViewportSize.Y;
             
              //Transform to world coordinates to get pick ray
              LocalPlayer(Player).Deproject(PickLocation, TouchOrigin, TouchDir);
            
              //Perform trace to find touched actor
             PickedActor = Trace(HitLocation, HitNormal, TouchOrigin + (TouchDir * PickDistance), TouchOrigin, true);
             
              //Casting to ITouchable determines if the touched actor can indeed be touched
              if(Itouchable(PickedActor) != none)
              {
                  //Call the OnTouch() function on the touched actor
                  Itouchable(PickedActor).OnTouch(Touch_Began, PickLocation.X, PickLocation.Y);
              }
             
              //Return the touched actor for good measure
              return PickedActor;
          }
          
          defaultproperties
          {
               InputClass=class'GameFramework.MobilePlayerInput' 
               PickDistance=10000
               ClickTolerance=2
          }

          Comment

          Working...
          X