#InputSystem moment #104893 plshelp

1 messages · Page 1 of 1 (latest)

small hound
#

Hello, im very new in comparison to alot of the people here.
prepare for some turbo-noob question.

Having troubles with 2D and i believe my solution involves ScreenToWorldPoint.
I for the most part know what i want to write to create a weapon that orbits my character, which rotates towards the cursor.

Currently having a bit of confusion..

For WASD And Spacebar I have been using Input.GetKeyDown(KeyCode.Space)
and the inputmanager

Looking for a really simple and short way to capture a screen position under the mouse-cursor into a Vector2!

my solution that DID not work was:

       private WeaponParent weaponParent;
[SerializeField]
        private InputActionReference movement, attack, pointerPosition;


 void Start()
    {

        weaponParent = GetComponentInChildren<WeaponParent>();
        
    }

 pointerInput = GetPointerInput();
        weaponParent.PointerPosition = pointerInput;

  private Vector2 GetPointerInput(){ ///bs for pointer
        Vector3 mousePos = pointerPosition.action.ReadValue<Vector2>();
        mousePos.z = Camera.main.nearClipPlane;
        return Camera.main.ScreenToWorldPoint(mousePos); ///who tf is screen to world and why are they pointing


    }```
 

and subsequently when adding this code to my script my character can no longer move.



https://paste.myst.rs/meum2c6e
#

this is the total code and above is the actual specific lines added

#

tldr

reef birch
#

why are you tldring code

small hound
#

i think i actually just solved my own issue

#

wait a sec

#

lolw

reef birch
#

wow nice

small hound
#

nvm

#

made it worse

reef birch
#

wow

#

not nice

small hound
#

my character can not move whatsoever when i implement this code

tall yacht
#

it's easier if you post a link to your code from a bin or paste site and remove all the unnecessary white space . . .

#

!code

undone meteorBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

small hound
#

oh

#

nice

tall yacht
# small hound

you don't assign the pointerPosition variable to anything . . .

small hound
#

hm

#

ah i see. The tutorial i watched just skipped that part

tall yacht
#

i'd watch it over again. seems a pretty important part not to have in the tutorial . . .

small hound
#

yeah its not there

#

but fixing that is just implemented new red features in my console

#

engine issues of some variety i

small hound
#

solution:

#

        difference.Normalize();

        float rotation_z = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;

        transform.rotation = Quaternion.Euler(0f, 0f, rotation_z + offset);```