Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: JonathanBurroughs on April 02, 2014, 02:55:44 PM

Title: [SOLVED] Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 02, 2014, 02:55:44 PM
Hello all,

I've taken a look at this thread here: http://hutonggames.com/playmakerforum/index.php?topic=3085.0

Following it's instructions I've run Set Mouse Cursor at the start of my game to hide and lock the mouse cursor.

However I'm still finding the mouse cursor drifting around in the scene, which makes using Mouse Pick tricky.

Ideally I want the Mouse Pick origin to be the screen centre, to align with a fixed screen position targeting reticule.

Is there a way to set this up?
Title: Re: Locking mouse cursor to centre of screen
Post by: Lane on April 02, 2014, 03:31:00 PM
Could you use a raycast from the camera instead? That wouldn't jitter.
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 02, 2014, 04:57:19 PM
Yeah, perhaps that's best. I'll swap out my Mouse Picks for Raycasts.
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 02, 2014, 05:52:47 PM
Ah. Actually this raises a broader question.

The Raycast action can't be toggled to call every frame. What is the best practice way to make it do so using states and events?

At first I thought I could just fire a ray whenever an action button is pressed, but ideally I'm going to want to be able to check the hit object every frame so I can do things like modify the target reticule appearance to indicate when an interactive object is targeted.
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 02, 2014, 06:09:13 PM
Here is what I'll attempt as a first stab:

- FSM on player camera has an event which fires a ray
- Ray detects the target gameobject and declares it as a global variable
- Event waits a short while (<0.1s)
- Event self-triggers

Any interactive gamobjects can compare themselves to the global variable. If they're the same and an action button is pressed then magic can happen.

Similarly my GUI system can evaluate the global variable to see if it should draw the standard or interactive target reticule.
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 02, 2014, 06:26:09 PM
Ah, found the Repeat Interval field on the Raycast action, so I don't need the self-triggering event.

Even so it's not working for some reason. Although I can't see why. I've switched on the debug view of the raycast and can't see the beam leaving the camera. So I suspect I've done something fundamentally stupid.
Title: Re: Locking mouse cursor to centre of screen
Post by: Lane on April 02, 2014, 08:06:46 PM
Is the repeat interval at either 1 or 2? Is the Distance set to a high number? Are there any colliders it might be running into on the camera or anything?
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 03, 2014, 05:27:23 AM
Heh, I wish it was any one of those. I've taken a stab at dabbling with all of them.

- Distance set to both 100 and -1
- Repeat interval set to both 1 and 2
- Tried casting from an empty object with no colliders and still nothing

I might just be doing something so fundamentally wrong that it's broken my entire approach.
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 03, 2014, 05:50:48 AM
So I've created a test environment with just a single cube with no collision emitting a debug ray.

(http://i.imgur.com/c8bnhRv.png)

When I run the game the ray doesn't appear in either the Scene or Game viewports. Strange!
Title: Re: Locking mouse cursor to centre of screen
Post by: Lane on April 03, 2014, 07:03:28 AM
You need a direction! =)

The vector for direction should be z = 1
Title: Re: Locking mouse cursor to centre of screen
Post by: JonathanBurroughs on April 03, 2014, 07:14:07 AM
Haha. That fixed it! Man, I feel so stupid. Thank you, Lane!