Teleporting mouse position to an object

I have a movement system where the player is able to teleport in a locked radius. I’ve hidden the cursor in the game and I’m using a game object to serve as the cursor which is spun around on the radius to choose where you want to move. The mouse is freely moved, its just not visible, and the direction in which you move is relative to which side of the player the cursor is on. I want the mouse position to teleport to the in game cursor that I’ve created every time that I click. I need this to happen because if I just keep the mouse still, the player keeps teleporting back and forth every time that I click because the mouse position is in between each of the teleport locations.

Is this possible?

Yes.

If you post what you have going so far, perhaps someone could even comment usefully on it.

The issue you will face is that the cursor is a operating system component, therefore you may have compatibility issues with different operating systems.

To avoid branching outside of the unity namespace, I suggest you do this instead.

  • Store a vector2 that is used to represent a mouse position.
  • When then mouse moves, change the position of that vector by the mouse’s magnitude.
  • When you click, set the vector2 to the corresponding position of that object you mentioned.

However, as I don’t develop much outside of windows. I cant say for sure that there would be issues with your original desired approach. Mono does an excellent job of translating code to different platforms. So… If you are set on your original method, check out this. It will require you to setup unity to work with the the System.Windows.Forms.dll however, which is another lesson in its own.