playMaker

Author Topic: Keep GUI Object/Cursor in Screen [SOLVED]  (Read 2293 times)

Palanysamy

  • Playmaker Newbie
  • *
  • Posts: 14
Keep GUI Object/Cursor in Screen [SOLVED]
« on: November 10, 2013, 12:35:01 PM »
Good afternoon!
I created a custom cursor that is controlled by Joystick. The problem I am facing is to keep the cursor inside the screen´s borders. So far I did:
I did:
Float clamp taking screen height and screen width into cursorheight and cursor width, and comibed these 2 floats in a new vector 3. But I dont know how to proceed from here (I tried vector3 clamp magnitude, but this just keeps the cursor in a circle)
Any hint, suggestion?
« Last Edit: November 10, 2013, 06:56:09 PM by Palanysamy »

Bjakuja

  • Junior Playmaker
  • **
  • Posts: 75
Re: Keep GUI Object/Cursor in Screen
« Reply #1 on: November 10, 2013, 02:43:23 PM »
Hi!

Here is what you can do to keep mouse cursor in desired position:
First create GUI texture (or add GUI texture component to empty game object) and set scale to  0, 0, 1
For texture use your desired cursor GUI texture then set your texture dimensions as you want, for example use 50 for x and y, add offset - 25 to x and y so it can be centered (you can divide your screen and set desired values as well). After that use actions that are provided on this image, get mouse x, get mouse y and store those float values, then use float clamp and clamp those values as you want every frame so for next step is to set position for that object in world space every frame (for x value use your stored value from mouse x and for y use stored mouse y). Last thing you want to do is to hide mouse cursor by using set mouse cursor action and check hide.
And that's it, you got your cursor on screen positioned on screen!

Cheers!

Palanysamy

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Keep GUI Object/Cursor in Screen
« Reply #2 on: November 10, 2013, 04:08:18 PM »
thanks Bjakuja!
this works good with a mouse, but not with joystick/thumbstick. I use the joystick input maginude to add it to the cursor s position vector. But i can´t figure how to prevent the cursor going out of the screen.

Palanysamy

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Keep GUI Object/Cursor in Screen
« Reply #3 on: November 10, 2013, 06:55:42 PM »
figured it out!
get axis horizontal,
get axis vertical
add them to empty var. ¨horizontal¨ and ¨vertical¨
clamp horizontal and vertical with screenwidth and screenheight,
set position, leaving vector empty and X with horizontal and Y with vertical.