Announcement

Collapse
No announcement yet.

(solved) How to get mouse coordinates in PlayerController?

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

    (solved) How to get mouse coordinates in PlayerController?

    Hi everyone,

    I'm trying to get mouse coordinates like deshribed in CreatingAMouseInterface artile, but its always return zero =(

    I can't find where is my mistake(

    VerytexPlayerController.uc
    Code:
    class VerytexPlayerController extends GamePlayerController;
    
    var IntPoint MousePosition;
    
    function UpdateRotation(float DeltaTime) { }
    
    function PlayerTick(float DeltaTime)
    {
        local VerytexPlayerInput MyVerytexPlayerInput;    
        MyVerytexPlayerInput = VerytexPlayerInput(PlayerInput);
        
        if (MyVerytexPlayerInput != None)
        {
            `log(MyVerytexPlayerInput.MousePosition.X);
        }
    }
    
    defaultproperties
    {
        InputClass=class'VerytexPlayerInput'
    }
    and VerytexPlayerInput.uc
    Code:
    class VerytexPlayerInput extends PlayerInput;
    
    var PrivateWrite IntPoint MousePosition;
    
    event PlayerInput(float DeltaTime)
    {
        `log("Input");
        MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, myHUD.SizeX); 
        MousePosition.Y = Clamp(MousePosition.Y - aMouseY, 0, myHUD.SizeY); 
        Super.PlayerInput(DeltaTime);
    }
    
    defaultproperties
    {
    }
    And log


    Looks like (MyVerytexPlayerInput != None) is true, beceuse I see log message, but why it always zero?

    There is no `log("Input"); message in log, is it normal?

    #2
    You haven't provided the most important information to be able to help you. What is your HUD class if you're using an existing one or which of the existing ones are you inheriting from?

    If you're based on UTHUD then in the PostRender event the super versions are not called. These do the important SizeX/Y = Canvas.SizeX/Y;. If this doesn't happen then SizeX/Y is never changed/set anywhere other than its initial initialization to 0. And clamping any value between 0 and 0 will of course be 0.

    Comment


      #3
      Thank you for answer, here it is

      VerytexHUD.uc
      Code:
      class VerytexHUD extends HUD;
      
      var const Texture2D CursorTexture; 
      var const Color CursorColor;
      
      event PostRender()
      {
          local VerytexPlayerInput VerytexPlayerInput;
      
          if (PlayerOwner != None && CursorTexture != None) 
          {
              VerytexPlayerInput = VerytexPlayerInput(PlayerOwner.PlayerInput); 
      
              if (VerytexPlayerInput != None)
              {
                  Canvas.SetPos(VerytexPlayerInput.MousePosition.X, VerytexPlayerInput.MousePosition.Y); 
                  Canvas.DrawColor = CursorColor;
                  Canvas.DrawTile(CursorTexture, CursorTexture.SizeX, CursorTexture.SizeY, 0.f, 0.f, CursorTexture.SizeX, CursorTexture.SizeY,, true);
              }
          }
      
          Super.PostRender();
      }
      
      defaultproperties
      {
        CursorColor=(R=255,G=255,B=255,A=255)
        CursorTexture=Texture2D'EngineResources.Cursors.Arrow'
      }
      VerytexGameInfo.uc
      Code:
      class VerytexGameInfo extends GameInfo;
      
      defaultproperties
      {
          HUDType=class'VerytexHUD'
          PlayerControllerClass=class'VerytexGame.VerytexPlayerController'
          DefaultPawnClass=class'VerytexGame.VerytexPawn'
          bDelayedStart=false
      }

      Comment


        #4
        I've try to do this

        Code:
        event PlayerInput(float DeltaTime)
        {
            //MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, myHUD.SizeX);
            //MousePosition.Y = Clamp(MousePosition.Y - aMouseY, 0, myHUD.SizeY); 
            MousePosition.X = 100;
            MousePosition.Y = 200; 
        
            Super.PlayerInput(DeltaTime);
        }
        But its zero anyway, how can it be?

        Also I check myHUD.SizeX in VerytexPlayerController - it have value 1600 (like screen resolution 1600x900)

        Comment


          #5
          In your PlayerController class, see what this logs:

          Code:
          if(LocalPlayer(Player) != none)
              `log(LocalPlayer(Player).ViewportClient.GetMousePosition().X @ LocalPlayer(Player).ViewportClient.GetMousePosition().Y);

          Comment


            #6
            Angel_Mapper
            Yes, it works fine. Log show right mouse coordinates. Thanck you very much!



            Problem, deshribed in first post solved, but there is 2 questions.

            1. Why there is no `log("Input"); message from event PlayerInput in VerytexPlayerInput.uc? (just want to understand)
            2. How can I pass Mouse Coordicates from VerytexPlayerController to VerytexHUD?

            Comment


              #7
              1) Looking at your code, it might need to be this:

              Code:
              class VerytexPlayerInput extends PlayerInput within VerytexPlayerController;
              2) The HUD is declared and set as MyHUD in PlayerController.

              Comment


                #8
                UnrealEverything, Angel_Mapper, Much thanks!

                Comment

                Working...
                X