playMaker

Author Topic: Help with Click Move To + Invalid areas  (Read 3278 times)

jess84

  • Hero Member
  • *****
  • Posts: 515
Help with Click Move To + Invalid areas
« on: November 04, 2013, 06:48:44 PM »
Hi,

So I've got my character movement working as a Click to move To. I'm detecting valid areas by filtering to only a particular layer.

However I have the following two problems;

1) If I click on a wall, and there is my terrain layer behind it, the character will move through the wall. (If I click on a wall, I want it to be ignored) The same goes for an interactive object if there's terrain behind.

2) When I click on a GUI object, the same thing happens.

Any pointers on how I go about limiting what is a valid click before moving the character to the new position?

Thanks in advance

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Help with Click Move To + Invalid areas
« Reply #1 on: November 05, 2013, 02:18:40 AM »
Hi,

 I think you'll need a pathfinding solution, else you will run into lots of troubles.

The other solution is to ignore the wall as you click, can you not detect that you clicked on a wall?

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Help with Click Move To + Invalid areas
« Reply #2 on: November 05, 2013, 07:12:53 AM »
Pathfinding would indeed be the best, but you can make a rudimentary system without it.

A lot of times the actions have the layer mask, which you can use to filter the floor as an intersection, but this would ignore any walls.

So if you're using raycasts for example just store the hit object and compare its layer to the allowed click-move layers. If its the floor, then do the move. If its not the floor, then don't do anything and return to the idle state.\

Keep in mind if you click on the other side of a wall then the character will just walk straight trough it to get to the "approved" position. Pathfinding resolves this issue.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Help with Click Move To + Invalid areas
« Reply #3 on: November 05, 2013, 10:44:31 AM »
Thanks for the responses.

I'm some way from being able to implement pathfinding, so some basic checks of layers will probably suffice for now.

Would this method also work for GUI Texture elements that I have on-screen?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Help with Click Move To + Invalid areas
« Reply #4 on: November 06, 2013, 01:07:09 AM »
Hi,

 Pathfinding is only for 3d world objects, not 2d elements unfortunatly,

You can find third party pathfinding systems that may work with 2d elements, but I doubt they will accept GUI textures anyway,

Bye,

 Jean

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Help with Click Move To + Invalid areas
« Reply #5 on: November 06, 2013, 07:42:49 AM »
I think you've misunderstood. I know what pathfinding is...  I'm talking about my problem of clicking a gui element, but the character moving to world space BEHIND that area.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Help with Click Move To + Invalid areas
« Reply #6 on: November 06, 2013, 08:08:10 AM »
Since the objective is to say that when we are hovering over gui, then player can't be moved, basically... Then we have a problem since there doesn't seem to be any way to detect that on the front end which means that your pathfinding solution would need a built in method for detecting when the mouse is over a gui element.

http://answers.unity3d.com/questions/30842/how-to-detect-mouse-over-gui-and-guilayout-element.html
Ironically, Jean made that post.

Unless there's some easier way I'm missing then you might be able to make a custom action like this
http://docs.unity3d.com/Documentation/ScriptReference/GUILayoutUtility.GetLastRect.html
To define that when your mouse is 'elsewhere' you send an event to enable character Click-To movement, and disable it when it is hovering over gui..... Maybe...

(edit)
Also... you could probably just put a big box (in 3d space) in front of the camera that matches up with the GUI size and space, change its layer and that would block the raycast. Depends on how complicated your GUI layout is though, maybe it wouldn't be feasible.
(/edit)
« Last Edit: November 06, 2013, 08:11:40 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Help with Click Move To + Invalid areas
« Reply #7 on: November 06, 2013, 09:13:16 AM »
Thanks for the suggestions.

Unfortunately the camera/blocking suggestion would be far too much work - I'm using a series of static cameras, rather than a camera following the player. And angle-wise it'd be a nightmare.

I'm going to experiment with adding something to my GUI elements - when I click them, it does something to prevent the click-move-to event being sent or processed.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Help with Click Move To + Invalid areas
« Reply #8 on: November 06, 2013, 09:25:05 AM »
Yeah I was thinking about that too, at first I figured it would be an equal nightmare to add an interrupt to every single gui area/button, but I guess it wouldn't be so bad if you flipped some global bool when a button is clicked, then the character reads that bool and jumps into a pause state, then right back. Just a matter of sequencing with some system of that sort.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D