playMaker

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

JonathanBurroughs

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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Locking mouse cursor to centre of screen
« Reply #1 on: April 02, 2014, 03:31:00 PM »
Could you use a raycast from the camera instead? That wouldn't jitter.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

JonathanBurroughs

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

JonathanBurroughs

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

JonathanBurroughs

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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Locking mouse cursor to centre of screen
« Reply #6 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?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

JonathanBurroughs

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

JonathanBurroughs

  • Junior Playmaker
  • **
  • Posts: 73
  • Some kind of independent game developer
    • @HiFiHair
Re: Locking mouse cursor to centre of screen
« Reply #8 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.



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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Locking mouse cursor to centre of screen
« Reply #9 on: April 03, 2014, 07:03:28 AM »
You need a direction! =)

The vector for direction should be z = 1
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

JonathanBurroughs

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