playMaker

Author Topic: Rollovers on certain objects (SOLVED)  (Read 2590 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Rollovers on certain objects (SOLVED)
« on: February 21, 2013, 06:00:27 AM »
Hi!
Not really a problem, just getting feedback in advance.

Im going to want certain objects in my game to be clickable, but to KNOW which, I need to get a warning/rollover effect. This could be anything, from the cursor turning into a hand, a symbol appearing at the bottom of the screen, or the object itself "lighting up" in some way.
But I want the effect to be the same for anything, an object or an NPC, just what happens when you click will be different.
The issues Im thinking about are:

What if the object is quite small? I dont want a pixel hunt, so maybe the clickable area needs to be bigger than the object itself.

What about proximity? I dont want to get a rollover effect from an object that is miles away, or thru geometry, only what is visible right now.

What various methods are there for doing this, what effects are nice, and what nice global way of implementing this can I do. (meaning that I want a generic FSM I can save as a template and just add to ALL clickable objects and NPC´s, and then change the function of the click independantly.

Thanks in advance!

MArk
« Last Edit: February 25, 2013, 10:55:32 AM by markfrancombe »

greg

  • Junior Playmaker
  • **
  • Posts: 68
    • View Profile
Re: Rollovers on certain objects
« Reply #1 on: February 22, 2013, 10:31:55 AM »
Thought about this myself. You can raycast a certain distance from centre of screen forwards, but raycast is expensive to do every frame.

For object identification:
- make pickup objects glow a bit, like L4D
- make a small label displaying their name or use, fade in above them if player is quite close

For minimal performance hit:
- just raycast when you hit the use key, check against only interactive layers
- send message to object you picked saying to "use it"

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Rollovers on certain objects
« Reply #2 on: February 22, 2013, 10:37:17 AM »
Bump?

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Rollovers on certain objects
« Reply #3 on: February 22, 2013, 03:37:48 PM »
I'm not sure if this will address what you're hoping for but the way i would approach it would be to have an object (that isn't going to be deleted, maybe on the player object itself) that works as a sort of "monitor" and have it using the mouse-pick every frame and transferring what it's over to a game-object variable. you might need to filter it so that it won't pick on colliders or other objects you might have in the scene that might interfere. Then, right under it, have a "set fsm gameobject" action every frame telling another fsm to update the game object variable in a new FSM (this can be on the same object in the scene and might make it easier to set up too.)

in this second FSM, have a sort of testing system that controls the overlay or other indicator you want to use (such as a projector that's over the object you want or a gui element that's at the mouse point or something like that.) to make it less intensive, you can have it only trigger whenever the game object variable has changed (the way it seems to work is that the mouse pick won't be removing or changing the game object variable every time it updates... so, a "game object changed" action should work with this kind of setup.)

So, in this one, let's say you're using a projector... and you have your objects set up with the proper layers (not tags... i made this mistake myself a couple times before i figured it out.) you can have this projector be the thing that has the monitor on it and the mouse pick action is set to ONLY look for what you've set in the layers as "objects to click" or "enemies" or "units" (etc.)

When you hold the mouse pointer over the object, if it's detecting this and you have the projector's position be set to the same position as the object you're hovering over, that should give you an indicator that will go to that position. if the object is moving, however, you might need to have the system adjusted a bit so that the "Set position" is always updating with the positional data of the object you want it to hover over.

I'll see about cobbling something up like this (since i want to add one to my own game as well that does something like this also... so, no time like the present, eh?) if you need some additional help (and it'll give me a chance to test out this idea since as things are, i'm only going on what i would expect it to do and haven't tested it myself yet... but don't let my lack of testing it stop you from trying, almost everything i learned i learned by trying things out and experimenting and you might come up with a different and/or more lean approach to do it on your own.

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Rollovers on certain objects
« Reply #4 on: February 25, 2013, 04:38:30 AM »
Thanks for the input, you give me many good ideas. I dont have the chance to work on this yet, as Im trying to fix another big challenge thats a bit more important. But mulling over your answer has defined for me more what I want.

Im pretty certain now that an object lighting up, either by a projector or a colour change is not what I want. I think it will be too disturbing to the "reality" of the scene. I think ideally a simple text at the mouse pointer position, is more relevant for my game.

As regards one of my points, that is finding a small object. Im happy to manually add in invisible field (trigger collider) to every clickable object, this way I can manually adjust the "hit area". An NPC can have an area that is about the same size, whereas an axe, or a gun can be bigger.

The object itself can contain the text field, either appearing at the objects location, the mouse location, or a defined place on screen, have to look into this.

I think Ill just mock up a quickie scene to see what mouse actions I have to use...

BRB

 :)

Mark


markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
    • View Profile
Re: Rollovers on certain objects
« Reply #5 on: February 25, 2013, 10:54:56 AM »
I just tried this now, and it was so simple I feel stupid for posting it. The key actions were:
Mouse Pick Event . Placed on the object or item (this could be an extra collider that has been enlarged SMALL KEY for example)
This action already provides Ray Distance as an option, so we can set it to be 10, rather than 1000
&
GUILayout Begin Area Follow Object. Here is how I decided to add the text popup, this required a game object, and will stick to it, so you could add this to an NPC.
Any kind of GUI thing can go after this, folowed by a GUIlayout end of course...

HERE...