Hi,
I want to use the mouse to control the ship, like we do with the keyboard or the gamepad. But I can not figure out how to bind it and use it from scripts. ¿Can somebody help me?
Best regards,
Hi,
I want to use the mouse to control the ship, like we do with the keyboard or the gamepad. But I can not figure out how to bind it and use it from scripts. ¿Can somebody help me?
Best regards,
Hi,
Welcome to our community!
The mouse exists in the Screen Space, your spaceship in the World Space. Look up the ScreenToWorldPoint method in the API. That’s what you need. Add Debug.Logs to your code to learn what values you are getting. That will help you find a solution.
See also:
Hi thanks for the answer. But there is something like:
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
in the new system?
Best regards,
Have you already taken a look at the manual? Looking for specific keywords could speed your research up.
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/QuickStartGuide.html
Here is another way to do the same thing. Look in Edit → Project Settings → Input Manager → Axes → Fire1 and Fire2
Take note that “Fire0” and “Fire1” correspond to the Mouse L & R buttons. There’s more to explore, but let’s stop here.
This code has been modified from the Delivery Driver script:
If you’ve worked through Delivery Driver, I think this will make sense to you. This script will allow the player to move fwd, bkwd, and strafe with w, a, s, and d. The player can also steer like a car with MouseL or MouseR.
I didn’t make this for the my GameDev project, but it is an offshoot of my Delivery Driver game so the code is very similar. I was working on it last night for something else, trying some things out.
Also note: This code is not complete for the purpose I have intended, so you might need to add a steering variable or multiply something to get your code to do what you want it to do. Just follow what the GameDev instructors show in the video.
The most important thing I wanted to show you here is:
This will make your mouse buttons work. I think you already figured out the rest.
I hope this is helpful.
Hi thanks for your answers, but both methods are not using the new input system.
Ahh…new input system…didn’t catch that.
Hi,
I tried this solution, but seems that is using old input system:
private Vector3 inMouse;
void Update()
{
inMouse = Input.mousePosition;
}
private uint TurretMovement()
{
Debug.Log($" mouse position: {inMouse}");
return 0;
}
This give me the next error:
when the project settings are already migrated to the new system:
Best regards,
Your old Input Manager is not connected, as you mentioned…it won’t be used of course.
I see the new Input System there below it in your pic. What’s in there?
I followed the steps in Space Assault lecture.
In the input system package I have:
And I already binded the keyboard with:
But I don’t know how succesfully bind the mouse
I already found it, is a little tricky (at least for me…). Is very simple you only need to bind the action with:
and select mouse position
But, here come the trick, in the code, you should get the value as Vector2 type
Thanks a lot for your efforts.
Coooool!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.