How to move gameObject to mouse position? Coordinates dont match!

Im using Screen To World Point… To transfer mouse position and use these vector data to set location to a gameObject (target reticle)

So that when i move up the mouse, the reticle moves up. And as well as horizontal mouse moves will move reticle as well.

And then I’ll make this value to change X rotation of my player spine so it aims up and down.

Now, there’s little info online about how to get mouse axis using the new input package system … So here’s how i did it to get it:

=== How To Get Mouse Position With New Input System For Visual Script ====

Project settings > input package > add new action in player and name it “mouseAim” (or whatever suits you)

Copy the default Look > Mouse(delta) action and pasted it inside mousePosition and changed delta to position.

Then regenerate nodes in visual script settings.

============

Now i can get mouse axis.

And here’s the issue… Mouse vector axis doesnt match canvas image UI rectTransform position (pos Y and pos X)… So i was reading about making a translation between world and screen.

Using this node “ScreenToWorldPoint”

But when i use this in the graph editor and enter play mode… i can see when i move the mouse in Game, the mousePosition is getting axis data. But everything after this screen to world is giving me fixed numbers. They won’t move unless i move the character. And tiny numbers of movement.

Is it because im using CineMachine camera following the player? Is there other way of using this node and im using it wrong?

Im confused. Please help!

Hi Litoid,

In which course and lecture are you?

I am not an expert on Visual Scripting in Unity right now, but what jumps at me is that you only connected the data pin from the On Input System Event Vector 2 and not the white execution pin.

I suppose you wanted to SetVariable on that event so that you remember the new mouse position in your mousePosition variable and then use the value from that variable on each update. Not sure that is supposed to work if you try to do that with only this one Set Variable for mousePosition. I could imagine that you need a separate GetVariable or so (is that a thing?) for that, since it runs in a different execution sequence.

Visual script for unity.

And i finished 70% of it. Only missing one is the bow and archer. Every type of game im extracting logic to adapt to my game. So far its great!

But sometimes i wonder for other mechanics… That carry similar logic, but needs a few tweaks.

Since i dont know all node names and what they do…
I only have my logic of what i want, how it should be and what triggers it.

Now im missing a “translation” between what i want, what c# people have done and get those into graph script.

Will GameDev launch any intermediate/advanced course on unity visual script?

The answer to this post i shared in Show section of the forum. I finally cracked how to make an object follow mouse position.

A UI sprite reticle. So where my mouse goes, the character targets. In a 2.5D shooting platformer.

The variable was for debugging purposes so i could quickly see mouse coordinates anywhere in the graph map. Not necessary.

The logic is complete! Check Show section of these forums for Unity Courses.

I was not getting a “translation” from 3d world to 2d world. I was missing a message between world and screen. Casting a ray fixed it.

Like camera shooting a laser into the world and get the location where this laser hits - as where in the world the mouse is.

I wished we had raycast lessons in this course… It wasn’t covered and it seems like an important fewture to create simplicity over complex solutions