Finding Mouse Movement

Hi, I’m trying to come up with a system that allows me to find the direction of movement of a player’s mouse in order to trigger different animations. Is there a simple way to find the direction of mouse input for a player? Thanks.

You should be able to figure something out from this … UDK | DevelopmentKitGemsCreatingAMouseInterface

Also another thing that can aid you loads, from your HUD class there is a Boolean that, if you activate it, it will show your hardware cursor bShowHardwareCursor or something like that. ( **class’HUD’. **

It’s position ( referring to hardware cursor shown in UDK ) will be the same, as if you programmed a cursor in both the flash movie and the Game.
It’s not the same to program a Cursor for AS3 and AS2 take that in mind.

If you use the canvas cursor of that tutorial it’s position will have offset and not the same sensibility as your other flash movies, as well as that it will render behind the scaleform movies.

( You should be able to figure something out from this … https://udn.epicgames.com/Three/Deve...Interface.html )
This tutoriak it’s fine, but if your cursor MouseX and MouseY in game it’s not the same as flash position, you buddy will have a problem. Post if you do and i’ll show solution.

So answering to your question after this all other information below about mouse input handling in scaleform and canvas, to find out the direction of the mouse anyways the canvas mouse part of the tutorial it’s pretty much a good point to begin at.

I guess I should explain what I’m trying to do more clearly: the game I’m working in is first-person, but I’m activating different melee animations depending on whether the player is looking up-left, up-right, down-left or down-right. So I’m not wanting to look at an actual mouse cursor, I’m trying to find what input the player is providing with their mouse so that I can determine which animation to place.

There you have 2 variables X and Y to fully construct what you want. From UDK | DevelopmentKitGemsCreatingAMouseInterface.

Alright so I’ve used that resource to try and implement what I want, however when I print the mouse variables I just get zeroes, no changes.

In my playerinput class I have:




var PrivateWrite IntPoint MousePosition;

event PlayerInput(float DeltaTime)
{
  // Handle mouse 
  // Ensure we have a valid HUD

    // Add the aMouseX to the mouse position and clamp it within the viewport width
    MousePosition.X = Clamp(MousePosition.X + aMouseX, 0, myHUD.SizeX); 
    // Add the aMouseY to the mouse position and clamp it within the viewport height
    MousePosition.Y = Clamp(MousePosition.Y - aMouseY, 0, myHUD.SizeY); 


  Super.PlayerInput(DeltaTime);
}


Then in my PlayerController:


function InitializeWarMouse()
{
      local WarPlayerInput WarPlayerInput;

     // Cast to get the MouseInterfacePlayerInput
     WarPlayerInput = WarPlayerInput(PlayerInput); 

     if (WarPlayerInput != None)
    {
        // To retrieve/use the mouse X position
        MousePosition.X = WarPlayerInput.MousePosition.X;

        // To retrieve/use the mouse Y position
        MousePosition.Y = WarPlayerInput.MousePosition.Y;
    }
    

}

Then in my Pawn class I try to access the variable:


function CheckMousePosition()
{  
    //local WarPlayerInput WarPI;
    local IntPoint Mouse;
    local WarPlayerController WarPC;

    WarPC = WarPlayerController(Controller);

    Mouse.X = WarPC.MousePosition.X;

    AOCPlayerController(Controller).ReceiveChatMessage("Mouse Position X Axis:"@Mouse.X, EFAC_NONE, true, true,"#00ff00");////////FOR_DEBUGGING_REMOVE_LATER
}
 

Any ideas on why this isn’t working?

I thought you wanted the 2d co-ordinates of where the mouse is positioned on the screen ? If so the section titled “I just want the mouse 2D coordinates!” in the document should be all you need UDK | DevelopmentKitGemsCreatingAMouseInterface

Well this is what I use for the reason of that, finding a relative direction on wich was the input from.

From PlayerController, wich has acces to playerInput, Make sure playerInput Exists and such, ehhh it’s just a part but so far it’s like that. So make sure it’s PlayerInput != none
if else `log("FROM PlayerController Tick() Error player input does not exist ");



//FROM PLAYER CONTROLLER 
event Tick(float DeltaTime ) //Some tick function that is per frame
{

super.Tick(DeltaTime);


   	if (PlayerInput.aMouseX > 0)
	{
	R=PlayerInput.aMouseX;
        L=0;
	}
	if (PlayerInput.aMouseX < 0)
	{
        L=Abs(PlayerInput.aMouseX);
        R=0;
	}
   	if (PlayerInput.aMousey > 0)
	{
        U=PlayerInput.aMouseY;
        D=0;
	}
	if (PlayerInput.aMousey < 0)
	{
        D=Abs(PlayerInput.aMouseY);
        U=0;
	}
        //R 0=right L 1=left U 2=up  T 3=thurst

	//wich will have last word! 
 }



@OmarWarOgre I know what you’re trying to do. I’ve played Mount & Blade. :wink:

Just extend PlayerController, and in your Tick event, record PlayerInput.aTurn and PlayerInput.aLookUp. Maybe keep track of a rolling average of the aTurn and aLookUp values for the last few ticks to smooth it out. That should give you what you’re looking for.

@Nathaniel3W thanks for the info. After messing around with things I’ve decided to use the player’s camera orientation instead, seems like a good option. However I’m having trouble with the second part: keeping track of the previous values and comparing them to the current rotation values.

The relevant code looks like this:




class WarPawn extends AOCPawn;

var rotator StoredRotation;


simulated function GetCameraSocketLocationAndRotation(bool bFirstPerson, out vector CameraLocation, out rotator CameraRotation)
{
     if (bFirstPerson)
    {
        OwnerMesh.GetSocketWorldLocationAndRotation(CameraSocket, CameraLocation, CameraRotation);
        GetParryDirection(CameraRotation);
    }
    else    
    {
       Mesh.GetSocketWorldLocationAndRotation(CameraSocket, CameraLocation, CameraRotation);
       GetParryDirection(CameraRotation);
        
        if (bIsMirror)
        {
            CameraRotation.Pitch = -CameraRotation.Pitch;
            CameraRotation.Yaw = CameraRotation.Yaw + 32768;
        }
    }

}

    
    
simulated function GetParryDirection(rotator NewRotation)
{
    
    local int TurningDirection;
    local rotator ParryRot;

    ParryRot=NewRotation;    
    
    AOCPlayerController(Controller).ReceiveChatMessage("GetParryDirection Rot:"@ParryRot.Yaw, EFAC_NONE, true, true,"#FF0000");/////////// 
    
    if(ParryRot.Yaw == StoredRotation.Yaw)
    {
        TurningDirection = 1; 
       
    }
    else if(ParryRot.Yaw != StoredRotation.Yaw)
    {
        TurningDirection = 2; 
    }

    ParryDirection = TurningDirection;
    StoredRotation = ParryRot;
    
}



The first function runs every frame, so the intention is that it will compare the present value against the value from the previous frame, and modify the TurningDirection int accordingly. Right now I’m just testing something very basic, whether it registers any change at all, rather than the full version which will take pitch and yaw into account to make 4 different parrying directions.

However when I run this code, the StoredRotation and the new rotation values are always the same, so it doesn’t work. Any thoughts why?

Is the camera moving when you move the mouse? Is the ReceiveChatMessage function telling you that you’re changing yaw when you move the mouse? It looks like all of that is set up correctly. What are you doing with TurningDirection and ParryDirection variables? With the code you’ve put here, it doesn’t look like you’re using them (and I don’t see where ParryDirection is declared), but when you’re moving the mouse, TurningDirection should be 2 and when the mouse is not moving, TurningDirection should be 1. Do you print those out somewhere not in this code?

Can you get StoredRotation.Yaw - NewRotation.Yaw, and print the result on the screen somewhere? If that’s not zero, then your code is working. It really looks like this should work…

…Except that you’re going to run into trouble when you go past 360 degrees. (And if you’re using camera rotation, then if you add in camera shake or a walkbob or similar, that could also mess you up too.) I think recording PlayerInput.aTurn and PlayerInput.aLookUp might work better, but it’s your game, your call.

The camera does successfully move with the mouse, and I print the right values. ParryDirection is a global variable that feeds into a separate animation function that changes the player’s parry animation.

I tried printing StoredRotation.Yaw-NewRotation.Yaw, which gives me a constant zero.

Checking the log (I inserted some code to print different stages in the process to the log), it seems like the code is being run multiple times per frame. Maybe this could be the cause?




[0209.32] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.32] ScriptLog: Setting new StoredRotation
[0209.32] ScriptLog: Sending Camera Values to GetParryDirection
[0209.32] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.32] ScriptLog: Setting new StoredRotation
[0209.32] ScriptLog: Sending Camera Values to GetParryDirection
[0209.32] ScriptLog: Stopping Resist Icon!
[0209.32] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.32] ScriptLog: Setting new StoredRotation
[0209.32] ScriptLog: Sending Camera Values to GetParryDirection
[0209.32] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.32] ScriptLog: Setting new StoredRotation
[0209.32] ScriptLog: Sending Camera Values to GetParryDirection
[0209.33] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.33] ScriptLog: Setting new StoredRotation
[0209.33] ScriptLog: Sending Camera Values to GetParryDirection
[0209.33] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.33] ScriptLog: Setting new StoredRotation
[0209.33] ScriptLog: Sending Camera Values to GetParryDirection
[0209.33] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.33] ScriptLog: Setting new StoredRotation
[0209.33] ScriptLog: Sending Camera Values to GetParryDirection
[0209.34] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.34] ScriptLog: Setting new StoredRotation
[0209.34] ScriptLog: Sending Camera Values to GetParryDirection
[0209.34] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.34] ScriptLog: Setting new StoredRotation
[0209.34] ScriptLog: Sending Camera Values to GetParryDirection
[0209.34] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.34] ScriptLog: Setting new StoredRotation
[0209.34] ScriptLog: Sending Camera Values to GetParryDirection
[0209.34] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.34] ScriptLog: Setting new StoredRotation
[0209.34] ScriptLog: Sending Camera Values to GetParryDirection
[0209.34] ScriptLog: Comparing ParryRot and StoredRotation...
[0209.34] ScriptLog: Setting new StoredRotation



And so on.

Just a bit of advice… Instead of logging all of that on every tick, maybe you should consider outputting your testing and debugging stuff to the HUD. Just make a Canvas HUD and in the DrawHUD function, do a Canvas.DrawText to write whatever you’re interested in.

I don’t know off the top of my head what calls GetCameraSocketLocationAndRotation and when. Actually, I’ve long wished that I could make every function demand as an argument the name of the function that called it. That sure would help in debugging later. I’m not sure if getting called multiple times per tick could be messing you up. But if you only changed the variables in Tick, then at least you could be sure that Tick is only being called once per tick.

That’s odd. What happens if you just print NewRotation.Yaw? Maybe that isn’t what we expect it is.

I tried using the Tick function to fire off the GetParryDirection function instead of activating it via GetCameraSocketLocationandRotation, and that now seems to work! ParryRot and StoredRotation are both class variables instead of local, and I have a seeprate function (StoreRotation) that I use to set the StoredRotation after the comparison with the ParryRot. Thanks for your help in solving this!