0
Planned

cursor raycast works in editor but not in built WebGL or Linu.x86_64

paddywwoof 4 months ago in Game Creator updated 4 months ago 5

Seems fine wile developing but built game doesn't work. I made a project:

Camera, Adventure Motor, Player, Cube to stand on, Cube with Trigger Cursor Raycast, Action message, Trigger on start to fire Action to lock cursor, Trigger on Esc key to unlock cursor.

I then added a global variable "camera_zap" to hold a GameObject, added the script below to the main camera, added a Trigger on left mouse click to the scene with action to run the script then changed the trigger on the target cube to check for variable changes, then call a condition to check if the variable value was the cube GameObject then finally fire the message action. Everything works fine.

```

using System.Collections;using System.Collections.Generic;using UnityEngine;using GameCreator.Variables;
public class Raycast : MonoBehaviour{ RaycastHit hit; public void Zap() { Vector3 ahead = transform.TransformDirection(Vector3.forward); if (Physics.Raycast (transform.position, ahead, out hit)) { if (hit.collider != null) { VariablesManager.SetGlobal("camera_zap", hit.collider.gameObject); } } }}

```

If you paste that into MS code it might unscramble it for you - not clear how to post code otherwise!

PS I've just tried modifying your IgniterCursorRaycast as IgniterCameraRaycast and it work exactly the same in the editor, but continues to work in the built game. It must be something to do with how the cursor locking is handled in linux or webGL or something (assuming this all works fine in windows or mac) Is there any advantage in not making it work this way generally (as the cursor has become invisible it seems dodgy to trust its location!)


Unity version:
2018.4.13f1
Game Creator version:
1.1.8
Under review

Hi; I'm unsure I understood this correctly as I lack proper context. I take that you're locking the cursor on the center of the screen and you're trying to detect clicks on an object using the Cursor Raycast Trigger, right?

I've compared your code with ours and looks like the difference is that you're transforming a local vector forward to world-space using the camera's direction, instead of using the the mouse position in screen-space.

If that's so, that probably means that the mouse position in screen-space isn't captured in WebGL. If you can confirm this is the problem, I'll investigate this further. Might be a problem from Unity that in WebGL or Linux it doesn't capture the screen-coordinates of the cursor when this is locked.

Marti, thanks for getting back. Yes, it is almost certainly something to do with Unity, and may be specific to running on linux or building on linux. I get the same issue with the linux native x86_64 test so I don't think it's WebGL specific. I've not tested on windows yet but might do that tomorrow (persuade my daughter to try it!).

Is there any advantage raycasting from the cursor (it seems to be invisible when locked whatever check boxes are selected)? If it's always in the middle of the screen then that's effectively the camera forward vector.


Anyway I'm happy using my modified igniter if you think this is too niche a problem.


All the best


Paddy

Planned

Not really any advantage. It's just a different approach to the same problem. I'll most likely change this in the next update, since there's no point at keeping something that doesn't work while there's a work around that does. Thanks!

Wait sorry. I clicked the Send button too quickly. There is. And that is when the mouse is not locked. If it isn't, the cursor doesn't have to be confined in the center of the screen.

My take is that maybe it's better to have another Trigger called "FPS Cursor Raycast" or "Screen Center Raycast"

Hi, I tend to agree that it's better to keep the old one and add a new one with a new name to differentiate it (someone might have used the functionality in some way). 


It might be a good idea to write the documentation before editing the code though: I'm not sure now what the two different existing mouse click raycasts do I thought the first one was specifically for locked cursor (which I understand is supposed to be in the middle of the screen but after googling unity forum discussions - at least in the past - did sometimes relocate the mouse pointer to a new 'invisible' location. People recommended setting the cursor location as well as locking it!) and the second one for non-locked cursors.

Paddy