playMaker

Author Topic: [SOLVED] Locking mouse cursor to centre of screen  (Read 2598 times)

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
[SOLVED] Locking mouse cursor to centre of screen
« on: April 02, 2014, 11:55:44 AM »
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?
« Last Edit: April 03, 2014, 04:14:19 AM by HiFiHair »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Locking mouse cursor to centre of screen
« Reply #1 on: April 02, 2014, 12:31:00 PM »
Could you use a raycast from the camera instead? That wouldn't jitter.

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #2 on: April 02, 2014, 01:57:19 PM »
Yeah, perhaps that's best. I'll swap out my Mouse Picks for Raycasts.

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #3 on: April 02, 2014, 02: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.
« Last Edit: April 02, 2014, 03:03:27 PM by HiFiHair »

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #4 on: April 02, 2014, 03: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.
« Last Edit: April 02, 2014, 03:21:15 PM by HiFiHair »

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #5 on: April 02, 2014, 03: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.
« Last Edit: April 02, 2014, 03:37:21 PM by HiFiHair »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Locking mouse cursor to centre of screen
« Reply #6 on: April 02, 2014, 05: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?

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #7 on: April 03, 2014, 02: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.

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #8 on: April 03, 2014, 02:50:48 AM »
So I've created a test environment with just a single cube with no collision emitting a debug ray.



When I run the game the ray doesn't appear in either the Scene or Game viewports. Strange!

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Locking mouse cursor to centre of screen
« Reply #9 on: April 03, 2014, 04:03:28 AM »
You need a direction! =)

The vector for direction should be z = 1

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • View Profile
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #10 on: April 03, 2014, 04:14:07 AM »
Haha. That fixed it! Man, I feel so stupid. Thank you, Lane!