How to get input intensity of gamepad using old input manager? - unity3d

I’m looking for a way to get the input intensity of a controller joystick when using a Xbox/PS5 Controller in Unity using the old Input Manager. Anything would help, I can’t find any resources on this subject, thanks!
Currently, the only results I’m getting are -1,0,1 using the old input manager

I think you already have your desired output. The method Input.GetAxis() returns a value between -1 and 1, representing the intensity of the joystick input. A value of -1 indicates that the joystick is fully pressed to the left, a value of 0 indicates that the joystick is not being pressed, and a value of 1 indicates that the joystick is fully pressed to the right.
To get the input intensity of a specific joystick, such as the left joystick on an Xbox controller, you can use the following code:
float leftJoystickIntensity = Input.GetAxis("LeftJoystickX");

Related

Bind and distinguish 2 equals joysticks new input system Unity3d

I am making a Pad Dance Game. I have 2 pad dances, they works like a joystick on Pc, they almost have the same number/button sequence(because they are not from the same company). The problem is when I click one pad and the other has the same gamepad number the action works in both player. I need the input system to distinguish if I am pressing the same number button from joystisck one or two. The image below shows how the input system detect the binding for the up arrow icon on the pad 1("botao1") and 2("botao11"), there is no difference if I am pressing joystick one or two. I tried to create 2 differents Action Map, didn't work, because the biding system don't recognize if am pressing joystick one or two. Any clues? Tks in advance
You need to duplicate the inputs, one for each pad (so for example "Left_Player1" and "Left_Player2"). You configure both inputs identically, except that they must have different JoyNum values.

Unity3D forcing object to a given orientation with minimum artificial effect

In my board game, the points are given by throwing 7 sea-shells cowry shell. These shells are dropped onto a sphere in Unity so they get rolled over randomly to different places. Once the rigidbody.isSleeping() returns true, I do a Raycast(from the belly side downwards) to figure out the orientation of the shell. If it is NOT a hit we know the shells belly is turned upside which means a point.
All is good and very realistic when in single player mode. Reason is I just activate the gravity of the shells and they dropped on to sphere, gets rolled randomly and when stopped i get the marks as stated above.
Now the problem is I am making the game multiplayer. In this case, I sent the randomly generated marks from the server and client will have to animate the shells to represent the marks. For example, if server send 3, out of 7 shells, 3 should have it's belly turned upside.
Trying to do this has been a major problem for me. I tried to transform.Rotate() when the velocity is reduced but it was not very reliable and sometimes acts crazy. Rotating afterrigidbody.isSleeping() works but very unrealistic.
I know I am trying to defy physics here, but there may be some ways to achieve what I want with minimum artificial effect.
I actually need some ideas.
Update - 1
After infor I receive below, I did found some information here, some advanced stuff here. Since the latter link had some advanced stuff, I wanted to start small. So I followed the first link and did below test.
I recorded the position, rotation & velocity of the sea shell with autosimulation enabled and logged them to a file. Then i used the Physics.Simulate() for the same scenario and logged the same.
Comparing the two tells me that data in both cases are kind of similar. So seems like for my requirements I need to simulate the sea-shell drop and then apply that sequence to the actual object.
Now my problem is how can I apply the results of physics.simulate() results (position, rotation, velocity etc..) to the actual sea-shell so the animation can be seen. If I set the positions to my gameobject within the simulation loop nothing happens.
public void Simulate()
{
rbdy = GetComponent<Rigidbody>();
rbdy.AddForce(new Vector3(0f, 0f, 10f));
rbdy.useGravity = true;
rbdy.mass = 1f;
//Simulate where it will be in 5 seconds
int i = 0;
while (simulateTime >= Time.fixedDeltaTime)
{
simulateTime -= Time.fixedDeltaTime;
Debug.Log($"position: {rbdy.position.ToString()} rotation: {rbdy.rotation.ToString()} Velocity {rbdy.velocity.magnitude}");
gameObject.transform.position = rbdy.position;
Physics.Simulate(Time.fixedDeltaTime);
}
}
So, how can I get this simulated data applied to actual gameobject in the scene?
Assume Physics are deterministic, just set the velocity and position and let it simulate on each client. Output should be the same. If the output differs slighly, you could adjust it and it may be only barely noticable.
Physics.simulate may be interesting to read, even if it's kind of the opposite of what you want.
You can throw in the client, record the steps in realtime or using physics.simulate (see point 2) and transmit the animation data as binary - then use it in the other clients to play the animation.

Changing the value of a joystick's Y axis

I'm currently trying to change the value of my joystick's (T.16000M) Y axis using AutoHotKey.
A little background first: I'm configuring some voice commands for Star Citizen, and I'm trying to write a script that would activate decoupled mode (so that I have 6 degrees of freedom), after which I would potentially adjust my ship's pitch by a full 180 degrees along the Y axis. I've discovered that I can't exactly do this using VoiceAttack alone, because within the game, only raw mouse input is accepted, and I cannot figure out how to simulate raw mouse input with either VoiceAttack or AutoHotKey.
Therefore, my next best solution would be to change the value of my joystick's Y axis, if this is at all possible in AutoHotKey. I've done tons of googling, and I've searched the entire documentation for any clue on how to achieve my goal.
I understand that JoyX, JoyY, JoyZ, etc., can be used to map joystick input to some other sort of control, like in this script that maps joystick input to the mouse cursor.
I hope this post is appropriate for StackOverflow; I wasn't exactly sure where else to put it. Maybe superuser?
Anyway, thanks for your help.
By the way, here is the code I was planning to use for the mouse:
MouseMove, 0, 500, 10, R
MouseMove, 0, -500, 10, R
This works in Windows, but not in the game, because the game only accepts raw mouse input.
To simulate raw mouse movement with AutoHotkey, use DllCall("mouse_event"... (Google it, there are tons of examples).
To get VoiceAttack-like functionality in AHK, see HotVoice
It is absolutely impossible to alter a joystick in AHK like you can alter keyboard. You need to create an extra virtual joystick and send output to that. See CvJoyInterface.

Need Unity character controller to make sharp 90 degree turns and not slide when turning

I'm using the first person controller for my characters movement. On a left arrow keypress, I'd like the character to instantly rotate 90 degrees and keep moving forward. Currently, when I hit the arrow key, the character makes the sharp 90 degree turn, but the forward momentum the character previously had takes a second to wear off so the character ends up sliding in the direction he was previously moving a short bit.
The closest example I can think of to visually explain what I'm trying to do is how the character turns sharp in Temple Run. How my game is currently working, if I had the character on a ledge make a sharp left turn, he'd likely keep the original momentum and slide off the edge right after he turns.
Since my character is running on the x/z axis, I'm wondering if there would just be some way to maybe swap the directional velocity/momentum? The speed the character had on the x axis would instantly be switched to the z when it turns and the other would be set to zero. I'm obviously open to any solution that accomplishes what I'm looking for.
I dug into the CharacterMotor class in the first person controller, but have yet to find what part I can tweak to accomplish this.
I'd greatly appreciate any help.
Thank you.
You can try to stop the velocity of the Rigidbody before turning.
this.rigidbody.velocity = Vector3.zero;
this.rigidbody.angularVelocity = Vector3.zero;
If you want the object to continue like it did, you can try playing around with it by saving the current velocity in a variable, setting it to 0, rotate it and then putting back the old velocity (still forward).
If it works with global vectors (so from the point of view of the world, not the object), then you can try negativing the velocity, actually causing it to go 'backwards'. I can't test it for now but either way I think you need to set the velocity to zero first before turning the character.

Mouse Position from Raw Input method

I am trying to get mouse position by using Raw input method. In the RAWMOUSE structure am always getting value MOUSE_MOVE_RELATIVE as usFlags that means am getting relative value of last mouse position. but i want absolute position of mouse. how to get absolute position value of mouse from Raw input ?
RAWMOUSE have exact same values that Windows received from mouse hardware (it could be HID USB/Bluetooth or i8042 PS/2 mouse etc). Usually mouses are sending relative movement, but some could send absolute - for example touch screens, RDP mouse (yay!).
So if you need absolute mouse pos (for example for game menu) you can use GetCursorPos API to get coords of Windows-rendered cursor on the screen.
But its not the same thing as sent with MOUSE_MOVE_ABSOLUTE flag in RAWMOUSE.
MOUSE_MOVE_ABSOLUTE is mouse movement in 0..65535 range in device-space, not screen-space. Here is some code how to convert it to screen-space:
if ((rawMouse.usFlags & MOUSE_MOVE_ABSOLUTE) == MOUSE_MOVE_ABSOLUTE)
{
bool isVirtualDesktop = (rawMouse.usFlags & MOUSE_VIRTUAL_DESKTOP) == MOUSE_VIRTUAL_DESKTOP;
int width = GetSystemMetrics(isVirtualDesktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN);
int height = GetSystemMetrics(isVirtualDesktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN);
int absoluteX = int((rawMouse.lLastX / 65535.0f) * width);
int absoluteY = int((rawMouse.lLastY / 65535.0f) * height);
}
else if (rawMouse.lLastX != 0 || rawMouse.lLastY != 0)
{
int relativeX = rawMouse.lLastX;
int relativeY = rawMouse.lLastY;
}
[Weird to see a 9 year old unanswered question as a top google search result, so I'll offer an answer.. better late than never!]
At the level of Raw Input API, you are getting the raw horizontal/vertical movement of the mouse device -- what the mouse reports at the hardware level.
According to the docs (I haven't verified) these delta X/Y values are not yet processed by the desktop mouse speed/acceleration/slowdown settings. So even if you started tracking the deltas from a known absolute location, you would quickly drift away from where Windows is positioning the mouse cursor, on-screen.
What's not clear from the docs, is what units or scale these relative X/Y values are reported in. It would be nice if it were somehow normalized, but I suspect it depends on the DPI resolution of your mouse. (I will find a mouse with adjustable DPI to test, and report back, if no one edits me first.)
Edit/Update: I got my hands on a mouse with adjustable DPI .. did some crude testing, enough to confirm the rough scale of the lLastX/Y values seems to match the hardware DPI.. eg. with the mouse in 1200 dpi mode, moving it physically 1 inch from left to right, generates a net sum of lLastX values ~= 1200.