playMaker

Author Topic: Having a raycast ignore another camera elements  (Read 8271 times)

mweyna

  • Full Member
  • ***
  • Posts: 242
Having a raycast ignore another camera elements
« on: March 26, 2014, 12:43:18 PM »
So I have two camera's in my scene, a UI camera with NGUI, and my main scene camera. One of my FSMs let's you select objects in the scene, but I want it to ignore any hits on objects in my UI Camera. As far as I can tell though, since the elements do not exist on the main camera, the raycast never actually hits them. Any thoughts how to approach this?



Here is my Raycast setup, all my UI elements are on the GUI layer.



Here is my camera setup, all my UI elements are on the "Camera" object, where my scene is viewed through "Camera.main"

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: Having a raycast ignore another camera elements
« Reply #1 on: March 27, 2014, 07:34:46 PM »
Any thoughts?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Having a raycast ignore another camera elements
« Reply #2 on: April 01, 2014, 01:17:38 AM »
Hi,

 all your UI is on a specific layer, so when you raycast I would simply use a layer mask and ignore all objevt on your UI layer.

Have you tried this?

bye,

 Jean

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: Having a raycast ignore another camera elements
« Reply #3 on: April 01, 2014, 01:49:46 AM »
Yeah the probably is not that I want to ignore the UI, but rather keep it so UI elements when hit do not cast a raycast beyond them. Right now, considering its casting from the main camera, not the UI camera, it doesn't register those UI elements. My UI setup is off to the side of the main scene setup and then through NGUI layered onto the main camera.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Having a raycast ignore another camera elements
« Reply #4 on: April 04, 2014, 06:33:22 AM »
Hi,

You need to then implement a two step process, you do a raycast on the UI, if you find nothing, then you raycast on out content layer. then the content raycast can only happen if the UI raycast did not returned anything.

 Bye,

 Jean

Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Having a raycast ignore another camera elements
« Reply #5 on: May 06, 2014, 11:30:51 AM »
Sorry to revive a slightly older thread, but I am completely stumped by this issue.

I have a similar problem (input system built & tested & working well before integrating NGUI, now button presses in the UI pass that input right through to the game as well, causing unwanted player movement). I have read numerous threads on both this forum & the NGUI forums, and still have no idea how to fix this issue -- mostly because I don't quite get how best to set up that raycast you mentioned.

Do I cast from the NGUI camera? Or the Vector3 location of the mouse click? Do I cast outward (Z: -1) from the click location towards the UI elements? Do I cast inward from the camera towards the UI elements?

So far I've tried variations of all of these things (along with some other botched experiments of my own) and nothing is working. No matter how I set this up (with or without layer masks, etc.) the button click registers both with NGUI and also with the game's input manager.

I feel I'm missing something extremely simple here, but I have run out of ideas... Any chance you could explain the two-step raycast setup a bit more?


Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Having a raycast ignore another camera elements
« Reply #6 on: May 06, 2014, 12:57:32 PM »
Maybe it's just simpler to post this, the response on the NGUI forums (from NGUI's creator) to the exact same question. Right before he also said "PlayMaker? You'll have to ask on their forums."

"You need to switch your game to use the NGUI event system rather than relying on Input yourself. Either that, or check UICamera.hoveredObject != null before proceeding with your own event handling."

Is it possible to do that second part, checking the UI Camera as described, with existing PM actions?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Having a raycast ignore another camera elements
« Reply #7 on: May 07, 2014, 08:58:10 AM »
Hi,

 Ngui Camera works like any camera, but I think that the problem is in the mixe up of colliders in your scene.
 Move your UI completly out of the frusturm and "world" space of other non ngui camera ( typically, move it 100 unit up your 3d world for example).

 then you rule out any collider interferance and can start debugging what's going wrong.

1:  When you do a raycast maye sure you properly use the layer mask, that's rule number 1.

2: disable everything non ngui, make it work and then added other stuff back in the world one by one. Thsi is how to debug such issues.

bye,

 Jean

Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Having a raycast ignore another camera elements
« Reply #8 on: May 07, 2014, 11:01:10 AM »
Thanks Jean, I appreciate the reply.

I do get the process of debugging & have disassembled, rebuilt, and shifted around nearly all of my existing systems several times over the past few days. So far, no luck.

The basic problem is that everything works, even when it shouldn't.  :) The movement controller works perfectly and the pause button/menu work perfectly. The issue is that the input is passed to both systems (NGUI and my own input controller, which is started off of a 'Get Mouse Button Down' state - from which is filters through a series of checks before processing a player move).

I just need to make the input go through one or the other system, not both. I will keep poking at this, but I still don't quite get how I am supposed to make use of the raycast when the NGUI elements are not using the main camera from which the ray is cast.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Having a raycast ignore another camera elements
« Reply #9 on: July 16, 2014, 07:45:21 AM »
Hi,

Indeed, it's asking for trouble to try and raycast yourself ngui stuff, I have always moved away from this.

 Can you explain why you need this?

 Bye,

 Jean

Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Having a raycast ignore another camera elements
« Reply #10 on: July 16, 2014, 10:01:55 AM »
Well, I worked around it, but...

I have a tap to move 2D game -- sort of the same approach as BattleHeart, if you're familiar with that game. You tap on screen & your character moves towards it. Pretty simple & I have all of that working through my own Input Controller FSM.

There is a second input controller for a full-screen minigame, which detects input anywhere on the screen.

When I added NGUI to build the UI, however, I added a pause button to the game. It sits at the top middle of the screen. This entire issue came down to this: Once the UI was in place, if I tap on the pause button, NGUI read that input but so did my Input Controller FSM -- causing my character to walk towards the top, middle of the screen whenever I tried to pause the game.

To be clear, the game DID pause, but as soon as it unpaused, the character continued moving towards the top middle.

All I wanted to do was to find a way to stop the input from being detected by any other input controller FSM *if* it was initiated on/at an NGUI button.

That's all, but I never was able to make it work quite right, until...

I worked around it by moving my pause button INTO the game space and out of the actual UI. I do not think that was the best, most elegant way to do it, but it works and I had to move on to bigger issues. :) The game is done now, and in review with Apple. I'll post info about it once I get the green light from them.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Having a raycast ignore another camera elements
« Reply #11 on: July 18, 2014, 08:24:08 AM »
Hi,

 pausing implies several assumption, it's like a "freeze", typically the speed of a rigidbody is kept so when you resume it has yet a bit more to travel if it had speed when you paused, so when pausing you need to kill speed of your rigidbodies.

Bye,

 Jean