#🖱️┃input-system
1 messages · Page 5 of 1
Are you reading and applying the input in Update?
yep
lookInput = GetLookInput();
ProcessLook();
This is the GetLookInput
private Vector2 GetLookInput() => new Vector2(inputHandler.lookInput.x, inputHandler.lookInput.y);
This is the look around
private void ProcessLook() {
if (playerSettings.invertLook) {
cameraPitch += lookInput.y * -playerSettings.lookSensitivity;
} else {
cameraPitch += lookInput.y * playerSettings.lookSensitivity;
}
cameraYaw += lookInput.x * playerSettings.lookSensitivity;
cameraPitch = Mathf.Clamp(cameraPitch, playerSettings.upperLookLimit, playerSettings.lowerLookLimit);
cameraEyeLevel.rotation = Quaternion.Euler(cameraPitch, cameraYaw, cameraEyeLevel.rotation.eulerAngles.z);
transform.localRotation = Quaternion.Euler(transform.rotation.x, cameraYaw, transform.rotation.z);
}```
With gamepad it's super smooth
I just noticed it's been duplicating itself when I load a new scene
what does this warning mean?
Rene most likely just did an oopsie there 😄
guess so haha 😛
you guys think this is gonna generate any problem?
https://forum.unity.com/threads/mouse-delta-input.646606/page-2 ... Looks like I'm experiencing a pretty common bug with calculating deltas, which hasn't been fixed since 2019.
How is input handler handling the input?
I would try creating a separate action for mouse delta to make sure there isn't any issues coming from the controller setup
OK guys
I'm very very confused about the input system. I started my project with the default InputHandler that comes with the thirdperson template
And it's working ok, i guess
thing is, i want to create a different interaction for my movement. For example, i want the character to dash whenever i double tap WASD. And thats just a new interaction. Got it
not sure how im supossed to get that with the functions i get like OnMove(InputValue value)
should i change it to be event based?
Every single video i watch tells me something different
I have even tried to create a new action like "DashLeft", add a binding to it to my A key, add the multitap interaction. Go to the script, do OnDashLeft(Inputvalue value)... and it doesnt really compute
im pretty lost and ive lost more time on this than im proud to admit, would apprecciate any help i could get
Will try that one. The input handler is getting the values normally by with a += context => ProcessLookInput(context)
I THINK I've got a pretty simple problem, any help would be greatly appreciated.
Ok so I can move around my UI with my controller just fine, but I can't actually press any of the UI buttons with my controller. Anyone know how to do UI input from controller? (I've found tutorials online of how to navigate with controller which works but I can't find anything on how to accept the controller input)
Fixed it
If you are using the new input system, you can always detect with "OnDeviceChange"
public void OnDeviceChange(PlayerInput playerInput)
{
isGamepad = playerInput.currentControlScheme.Equals("Controller") ? true : false;
}
in this case -- I have two control schemes set up in the input system which I named "KBM" and "Controller"
that's what I was doing but when I went to assign the function to player Input it wouldn't appear
I tried to do at least
so even setting up 2 separate control schemes inside the input system, the result is always false?
yep
ok so i have done some further testing around my wasd and arrow key problem.
if i use two different input actions asset files (one for player input, one for the event system / input system ui input mpdule) i can use wasd and arrow keys as normal
if i have the wasd and arrow keys action bindings be under a up/down/left/right composite it works.
so:
if both the ui and player input use the same input action asset while UI/Navigate has wasd and arrow keys, then i can't use those keys for player movement unless i put those under a up/down/left/right composite.
that seems very weird, and i don't think i had those problems before updating from 2022.1.11f1 to 2022.2.20f1
oh it's even weirder than that. i thought that the composite worked in general. but seemingly only when it's taken from a new input action file and renamed.
both files (named 3333 and 2222) are new. in 2222 i removed all actions beside Move, and then removed all bindings beside the WASD composite, then renamed move to WalkRight
in 3333 i remove all actions, then made a new action called WalkRight, then added a up/down/left/right composite. and added the bindings for WASD, then renamed the composite to WASD, then made sure that all the properties of the action, composite and individual bindings are the same as 2222. but that one don't work
the code they are supposed to run is:
so the fault can't be with that
the player input looks like this:
(although Actions field uses 2222 when i was testing that obviusly)
event system looks like this:
hey all im having some real issues of my onTap triggers after my OnTouch event. does anyone have any idea how to handle this?
Explain your issue
basically I have a ui im trying to show and hide. the default is to hide on user touch but allow the user to tap the screen to show on and off the menu
maybe I have to change my ontap logic to just somehow check if we have already turned off
basically my primary touch always triggers and conflicts my ontap logic
Does this code that I took from Unity's manual works?
you tell us
Ok then
Trying to make a Dash ability for my character, would this be correct setup for such a thing?
any smiple way to trigger tap and press separately?
currently they are always together
Hey folks ,this might be a stupid question but is there a way to use the generated C# class when querying a PlayerInput object directly?
Like right now I'm doing playerInput.actions["Move"].ReadValue<Vector2>(), but I'd like to somehow use the Input Action Assets generated code and do something like playerInput.actions.testMap.Move.ReadValue<Vector2>();. I'm using different maps in multiple places and being able to use strongly typed names as opposed to strings would make it easier to know which map I'm using where and avoid breaking changes going unnoticed. Thanks!
no
PlayerInput and the generated C# class are two different approaches to doing the same thing.
Also if you're doing this: playerInput.actions["Move"].ReadValue<Vector2>() there's probably not a great reason for you to be using the PlayerInput component in the first place.
Unless you're doing local multiplayer
That's exactly what I'm doing 😄
well, no then 😛
I'd be fine with migrating away from PlayerInput, I'm still getting my bearings with this system. I like it a lot but I feel like I have some gaps of understanding
If I ditch PlayerInput, would it be possible? I don't see how to then grab a specific player's input from the action map itself
generally with PlayerInput you don't access actions manually
generally you use one of its modes - typically send messages or unity events
to listen for input
If you ditch PlayerInput you will have to manage all the nice local multiplayer stuff yourself
like device management/ assigning players to devices etc
Hmm... In a way it would make some things easier for me, but realistically looking at the underlying source for PlayerInput I think it does more than I'm willing to deal with by hand
Well, I appreciate the answer! I'll keep playing with it and maybe switch to constant strings to at least get a tiny bit of safety
Is there any way to store System.Action<InputAction.CallbackContext> in a terser delegate? I tried making a delegate "delegate void ControlAction(InputAction.CallbackContext context)" but when I tried assigning it to an InputAction it said it couldn't cast ControlAction to System.Action<InputAction.CallbackContext> (even though the parameters are identical)
I just want to avoid writing System.Action<InputAction.CallbackContext> all the time.
Currently i'm doing a using alias by doing "using ControlAction = System.Action<InputAction.CallbackContext>" but I'd rather just define one delegate that's equivalent to System.Action<InputAction.CallbackContext> and be able to use that directly.
Looks like your code is trying to access an axis that is not set up in the input manager.
e.g. via GetAxis or GetButton
yes i understand the error, but its the name of the input thats wierd af
cos the only time im asking for input is the G button, which i have configured
the rest just started happening, and now i cant write in my inputfield
Something in your code or a plugin / asset you've installed is trying to use an axis called "RG Compressed BC5"
its the inputfield
but how do i fix this
reinstall the base plugin? if thats even possible
input fields don't generally read input axes directly
you can click on the error
and see the fulls tack trace
to get a better idea of the source of the problem
it leads back to the inputfields BaseInput.cs script, and the input module
also the eventsystem, but thats just UI stuff
Ok so check out your input module
what axis bindings do you have set on your input module
nothing more than what comes preloaded
and one for f and b
show a screenshot of your input module? And make sure there aren't any other input modules in the scene
just to double check, do you mean Input Manager?
Hey! I've been messing with this for hours and I'm losing my mind. I'm getting this error. All it is is the ThirdPersonController script and I changed like 2 lines because I'm using Mirror and want to make sure the player has authority. http://pastie.org/p/6jIbJpP4jVAtcSLBU4ywBl
no
I mean input module
looks like your main cmaera has been destroyed and you're still trying to access it
then this
It's a component
on your EventSystem gameobject
show the inspector for it
yes the StandaloneInputModule
Yep your axes are all fucked up on that
xd
I would recommend deleting your event system object and creating a fresh one from the menu
that's where those weird axis names are coming from
ohhh you think its a camera issue? I get the error as soon as i try to move the character with an input
yes ok thnaks
yes look at the code on the mentioned line. The camera is the only thing being dereferenced
sorry i wasnt trying to sound rude lol. so I took a look and the camera reference wasnt on either of those lines
could this be the issue? im afraid to click it because im not sure how to reverse it lol
it was the camera. words cant express how much you helped me!!
Yes and to be clear the camera is referenced there on line 278/279
Hey! How can I call a method every frame that the click button is pressed? I know I can check the performed and cancelled and make a bool isPressed, but I'm wondering if there is any way to call performed every frame that is pressed
I've not looked into it lately, but a bool is probably the quickest solution, such that you have to poll that input. Otherwise dig around on the forums for some alternatives cause I've ran into a few previously.
Polling in update or starting/stopping a coroutine on started/cancelled
I started a new indie horror game project with my friend and I'm getting this problem;
I am using an FPS Controller and Unity's character controller asset.
Please let me know if there's a way to code camera movement for playstation 5 input 🙂
(sorry for bad video quality)
better quality version
I have objects in my scene with colliders, and i can trigger OnMouseOver on them, and i can raycast to hit them (as shown in the below code). But, if i move the object at runtime, i can only hit it/hover it if i put the cursor on the original position of the object. I checked that the collider is indeed following. Any ideas?
can you show a video or something of the issue?
I don't see anything immediately wrong with the code...
tomorrow :/
Okay so, i did a recording. This is an outline that i enable OnMouseOver on the game object, but it triggers only at the original location of the collider, even if it moves on runtime
your object isn't marked as static in the inspector or something is it?
also what is logging
"hit something...: <name"
Its not static. See the code i made above to raycast. Im trying to figure out what is hitting what 🙂
right so
what is it logging?
It also logs the right objekt, but on its original position if I move it
Can you add something to the log statement?
Debug.Log("hit something..." + selection.name, selection.gameObject);```
add that second parameter
and then when you see the log, click on the log one time and see which object it takes you to in the hierarchy.
but also.. can you do the log in OnMouseOver? That's where the highlighting is happening right?
I need some help with the input system and I can't figure out how to fix it
whenever I load a new scene (in this case Level 2 from Level 1), my input system stops working and I can't move my player anymore
Is there a built in way to detect whether you've release an input with unitys new input system?
Similar to using an InputValue and value.isPressed?
I'm looking to detect when a player has released a button with the new input system.
depends.. so many ways of doing it
InputAction.WasReleasedThisFrame is one
Any insight specific to a jump function in a character controller?
the one above is the simplest
there is also ButtonControl.wasReleasedThisFrame
subscribe to the canceled event on the action
or
Do what Null said
or
Check if the action is in the canceled phase
and several others...
Also it clones my player input action asset
@austere grotto @sullen lintel Thank you so much 🙏
where are you initializing your PlayerInput class
persist it maybe /
Every level just has a player prefab because the game is on a level-by-level basis
they actions variable on PlayerInput just clones itself or something when a new scene is loaded
like this (I just dragged the level 2 scene into the level 1 scene)
which script is ur player input on
the Player gameobject
I'm hooking into the right-click input action used by the ui input module and trying to listen for when it is clicked down. im struggling to distinguish between the press and release stages of a right click.
the action.performed event is invoked when pressed and released, but the started and canceled are never invoked. any tips on how to tell if the right click is pressed or released when the only event that works is performed which fires for both?
ah looks like ctx.ReadValueAsButton() returns true on press and false on release
You generally shouldn't touch that input action
should make your own
with action type: button
and no interactions
by default started will happen when it's first pressed. canceled when it's released.
Interesting. Any insight into why? I need to know whenever a ui game object is right clicked and since input modules don't expose events for this I was going to do my own raycast
DOn't do your own raycast
Don't hook into the input system
use the event systenm
Put a script on the button with IPointerClickHandler
and read the mouse button from the PointerEventData
In this case I cannot use that interface for structural reasons
I don't know what that means but that's the right way to do it
explain your "structural reasons"
You can also use the EventTrigger component to get the callback as a UnityEvent
This is the field you need to read https://docs.unity3d.com/2018.3/Documentation/ScriptReference/EventSystems.PointerEventData-button.html
the input action isn't going to tell you if the button was clicked at all. It will run for clicks anywhere.
I'm working on a context menu system. Any UI in any scene may have a component which implements an interface which provides items for said context menu. These components do not have a reference to the context menu system, they simply provide items when asked. I cannot easily have them all reference the context menu and tell it to Show, and I do not want to use a static. Thus I want a single, higher level input component that handles detecting clicked game-objects and asking them for their context menu items.
YOu can use events to invert that dependency
How's that?
that's what events do, they invert dependencies.
static event would be simplest
of course
with a sender param
but you could also have your context menu syustem susbcribe to every button if you insist on avoiding static
either way one of these things is going to have to reference the other
The ContextMenuUI does not know about all the other ui across the app which should show a context menu when clicked. It is simply a view for a list of context menu data
you're going to need to devise some way for these things to get data to each other
that's probably going to be through some kind of singleton or static event.
even if it pains you
the alternative is much nastier
doing manual raycasts etc.
I don't see why?
because you're duplicating work the event system is doing already
another option is some slightly hacky stuff reaching into event system and/or the input module:
https://forum.unity.com/threads/global-pointer-events.283895/#post-1958628
Sure but is it really that big of a perf hit to do on a right click? It's makes everything else much easier. Everything is decoupled, simply implement some IContextMenuItemSource on any component on a UI object that provides relevant menu items and just like that it works.
But yes my next step was going to be modifying the input module to expose an event
InputSystemUIInputModule already provides GetLastRaycastResult so I may just be able to use that. I haven't confirmed the order of operations yet tho (whether separate right click event is invoked before m_PointerStates is updated int the input module)
This test seems to work. No extra raycasts and no input module modifications
public class ContextMenuInput : MonoBehaviour
{
[SerializeField] private InputSystemUIInputModule inputModule;
private Vector2 _pressPoint;
private void OnEnable() => inputModule.rightClick.action.performed += OnRightClick;
private void OnDisable() => inputModule.rightClick.action.performed -= OnRightClick;
private void OnRightClick(InputAction.CallbackContext ctx)
{
var pressed = ctx.ReadValueAsButton();
if (pressed)
{
_pressPoint = inputModule.point.action.ReadValue<Vector2>();
return;
}
var result = inputModule.GetLastRaycastResult(0);
if (!result.isValid)
return;
var releasePoint = inputModule.point.action.ReadValue<Vector2>();
if (Vector2.Distance(_pressPoint, releasePoint) > 1) // Mouse was dragged
return;
string gameObjectPath = "";
var parent = result.gameObject.transform;
while (parent != null)
{
gameObjectPath = gameObjectPath.Insert(0, "/" + parent.name);
parent = parent.parent;
}
print($"Clicked: {gameObjectPath}");
}
}
Hey peeps, would it make sense to add a way to confirm a player should join in PlayerInputManager? I guess this is more of a a feature suggestion than a question, but it would be nice to be able to accept/deny a request. For example, if I only want the player to join when playing start rather than any button, the class doesn't seem to have any logical override point to add it in
The logical in-game concept of "joined" doesn't need to match the input system definition
That's fair, I could just listen for new players joining, but then put them in a holding state until I get the input I want
Thanks!
My only concern would be to miss the original input that triggered the join if it was already what I wanted, but I guess I'll play with it to see if it's actually an issue
Yep exactly. You could then even do all kinds of things like say "hold start to join"
And require a short holding time or whatever. Could have a separate action map for the holding state even.
Interesting, I'll play with it thanks for the suggestion!
Getting some weird drift on my right xbox controller joystick while idle.
I've tried setting the deadzones with no change..
any ideas?
Can this be solved in unity or is it a hardware issue?
Yeah will have to grab another nearby I just had one handy thought it odd to drift this bad, probably hardware its an older controller.
Hi again. So, i recorded a video of the issue, and a screenshot of the inspector + code. Notice how the rigidbody on the sphere doesn't let it fall down, and how the hover effect is only triggered at the original spot. This is true for any object in my scene. There are no scripts enabled, its not static and i checked that the project settings for Time is fine.
Do you have:
- Time Scale set to 0?
- Automatic physics simulation disabled?
- time scale set to 0, no
- i have no code that disables it. How can i check that?
check in your physics settings
maybe show screenshot of them
Nope
see how you have Auto Simulation disabled
that's your problem
!!! you are right!!
stuff still doesn't fall to the ground, but the hover works! let me test some more
as for falling to the ground you have gravity set to 0
Okay so the physics settings is preventing that, i see..! which is good i think, for this project 🙂 Thank you SO much!! i have been stuck on this issue for hours and hours
If you want to leave physics simulation disabled and still have your hover stuff work, you can manually call Physics.SyncTransforms() each frame to update the collider positions to match your objects moving around.
Oh cool! but isnt that what the auto sync transforms would do?
auto simulation syncs transforms but it also does a lot of other things you might not want
like resolving collisions
also, is it bad to have it disabled, if you want to make a game like a Moba? is it generally recommended to leverage the physics system? i'm using navmesh agents
ah ok
If you want collisions etc to work you'll want to leave the physics simulation enabled
Awesome. Thanks a million for the clearup..!
Question, is there a way to reference the connected controllers and assign them to their respective player when moving to a new scene? Right now it seems to be decided by whoever clicks a button the fastest.
Im just gonna use don't destroy on load or something
does somebody know how I can make it so an interactive rebind will only work on axis
or would that be automatic
cause I don't want that players can accidently rebind movement (currently Vector2) to like, ... the A button
hello everyone, does anyone know a great tutorial for shooting with the input system
Hey, does anyone know how to navigate UI using a joystick with the new input system? 🙂
throw one of those bad boys on the singleton game object you have your event system added to. Its also a good idea to create a new schema for your UI actions.
add this script component onto each of your UI elements you want to paginate over. read more about it here https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-SelectableNavigation.html
Should work by default
Hey, just wondering if there's something wrong with having two instances of PlayerInput in two different scripts. I have an instance of it in my first script, and when I Debug the Vector2 movement it works perfectly fine. But its not working with the second script. It's doing the exact same thing code wise but I keep getting (0, 0). Even without the instance in the second script I can still access its parameters (I.E. input.CharacterControls.Movement.ReadValue<Vector2>(), but I get an object reference error without it. Any suggestions?
Hello everyone, I'm trying to use the 'new' input system to create a local multiplayer game in which the first player uses WASD and the second uses the arrow keys. I don't know why, but only the last player added to the scene can use the input system.
What I did:
- Create the Input Action and configure 2 action maps (player1, player2) each one with their own actions and bindings.
- Defined Player Input for each player, setting the default scheme and map for each one, and changing the behavior to 'Invoke Unity Events'
- Set the callback context for 'Move' in Events
- Defined public void onMove(InputAction.CallbackContext context) {.....} in PlayerController
And that's it. I can't manage to get both players moving, only the last one.
You should only have one action map. Two control schemes
i'm having a really odd issue with the InputSystem and would love some help! I'm building a multiplayer game, and my player prefab has a PlayerInput component directly on the prefab's root object.
When connecting to the game as a remote client, the PlayerInput component just doesn't fire events. However, if I run the client in the editor and toggle the PlayerInput off/on again at runtime, it starts working.
Seems like there's an issue with the other player prefabs in the scene all having their own PlayerInput and they're conflicting with each other on the local client.
Is there a best practice I'm missing with PlayerInput? What's the best way to deal with this component in multiplayer?
For networked multiplayer? Don't use it!
It's really for local multiplayer
And you definitely don't want the other player objects to have active ones if you do use it.
i'm not using the InputSystemManager or anything. only reason I really wanted to use this component is for the interactive rebinding features.
You don't need PlayerInput to get interactive rebinding
this was my thought too -- so i set the player input component disabled by default in my player prefab and enabled it conditionally in code, but then it just didn't respond at all.
i need InputAction though and don't know of any other way to utilize them but through PlayerInput or the generated script file
Generated script file
InputActionReference reference
InputActionAsset reference
Direct InputAction on the script
ok. so multiple PlayerInput components across different prefabs create some sort of conflict (doesn't mention much about this under known limitations in the docs), and the best solution is to just use a generated C# class from the action map?
it seemed like the last activated player input component was the one awarded control over the input scheme, which would explain why toggling it off/on again would put it at the top of the stack and give it control again
but i don't understand why it didn't work for me to just set all the player input components to be disabled, and only enable it for the sole local client
So I had my InputAction generate code, but I am not sure how to get it. I can't make a variable to assign the generated code to. So like the code I generated is called GenericInput with an action Interact. How do I get to that from the InputAction?
found it
Is it true that if you use generated code, the keybinds can't be rebound at runtime?
No
Thank you for your answer, that didn't solve the problem but still helped. It seems Unity don't allow 2 players using the same device so you have to force it by code.
Hey guys! Can I ask question about the old Input Manager here too?
hi everyone, im trying to make a topdown game in 2d, i have this code to rotate weapons but it only works with mouse input. Is there a way to get something similar to work with controller/joystick as well using new inputsystem? this has stumped me for like the past 2 days
My Controller Haptics are not working, any help would be much appreciated, here's my code (I'm using a Nintendo Pro Controller connected by bluetooth to my windows laptop)
IEnumerator SetControllerHaptics()
{
if(controllerCheck.usingGamepad)
{
Gamepad.current.SetMotorSpeeds(0.5f, 0.5f);
yield return new WaitForSeconds(1);
InputSystem.ResetHaptics();
}
}
i can't understand how to make the input's code
Why do i need to give a Private void and add an "On"X thing?
Because that's how PlayerInput works
What isn't working about it?
It's just not vibrating my controller
is the code running?
Have you added Debug.Log to verify?
and also
if i want something to move with the Wasd keys
'll need to put the Private void name the input action im using and then
should i say GameObject.Get<vector2>?
no
have you considered following a tutorial or some examples?
've been trying to see
maybe im distracted with something idk
I've been going through the Unity Open Project ("Chop Chop") for architecture examples and I was reading up on how they're using the Input system. They're generating a custom c# script (which is what I've used in the past)... but I've heard there's a better way to use the Input System so it's more flexible for multiplayer applications - using the Input System component. Does anybody with experience using the Input System have any thoughts on this?
Just looking for advice from some old hands.
PlayerInputManager / PlayerInput is the simplest way to set up local multiplayer
it gives you mostly automatic device management
Yes I have
where did you put a log?
I just printed a log to the console
where
In the coroutine
outside and inside the if statment
I've been stuck on this for while and I'm pretty sure it's not the code
So this is doing the whole thing through components. I think you were the guy I was talking to about this before. Would you say there are many downsides to doing things this way? In your experience, would you say you could easily use the Scriptable Object 'Channel' pattern with this? I guess you'd put the PlayerInput/PlayerInputManager on a gameobject in a persistent Initialisation scene...
Are you sure switch pro haptics are supported in UNity?
I'm actually not sure, do you know how I can check that?
seems kinda iffy
"implements basic gamepad functionality."
good chance that doesn't include haptics
I should try another controller to see if it works
I don't have one on me right now but I can get one soon, thanks for the help
Sorry to bother you again, @austere grotto , but would you say there are downsides to using the Input System through the PlayerInput/PlayerInputManager ?
sure, you're locked in to handling input through that component.
Could I not also do a custom C# script? I'm... not sure what the problems of being locked into handling input through that component would be. If it's basically... serving the input I've set up in the Input System to me, then what are the issues? Sorry to keep bugging you, I'd just love to game out what I need before I start this project.
It's really hard to explain. Better for you to play around with PlayerInput, get a feel for how it works, and decide whether your game is workable with it.
10-4. One last one? As above, would you say you could easily use the Scriptable Object 'Channel' pattern with this? I guess you'd put the PlayerInput/PlayerInputManager on a gameobject in a persistent Initialisation scene. No worries if you can't respond to this, figured I'd take a shot. =)
I'm actually not familiar with the ScriptableObject "Channel" pattern.
Gotcha, no probs, thanks. =)
Is that like using an SO as an intermediate reference that multiple objects have reference to in order to communicate with each other?
Yeah, basically... Hang on.
In this second devlog, we look at how we employed ScriptableObjects to create a flexible and powerful game architecture for "Chop Chop", the first Unity Open Project.
🔗 Get the demo used in this video on the Github branch:
https://github.com/UnityTechnologies/open-project-1/tree/devlogs/2-scriptable-objects
(compatible with Unity 2020.2b and la...
yeah ok, figured
I'm thinking 'yes', but I've yet to sit down with it (and I'm about to hit the hay now, so... =D)
I don't think there'd be any problem using such a Channel approach as long as you're comfortable with using and creating delegates dynamically. You'd need to have the SO basically do a Dictionary<Player, SomeDelegate> to do this properly
since the players are dynamically spawned with PlayerInputManager
...Right. Okay. I'll have to think about that. =) Thank you for your advice.
in case this helps anyone else using PlayerInput with Netcode for GameObjects, I eventually landed on storing a singleton instance on a global game object in DontDestroyOnLoad. This way there’s only ever one input component in the game at a time.
Could someone link a good tutorial on how to use generated code for the new input system. I have it all setup, but my actions aren't being performed, and not sure why.
never mind, had to call enable on it.
when using Debug.Log(Mouse.current.scroll.ReadValue().y); What does the 120 or -120 signal when scrolling ?
I find a bit odd from the old Input system one of just 1 or -1.
docs just say The input from the mouse scrolling control expressed as a delta in pixels since the last frame. Can come from a physical scroll wheel, or from touchpad gestures.
just wondering to what is the old mouseScrollDelta -1 or 1
I'm guessing magnitude?
Not sure it can be counted as magnitude as its only about the delta Z value with the scrolling (i believe its z)
But its kinda the same deal either way i think
yeah , maybe the new input one shows how many pixels in one scroll , because if I do it fast enough I get 240 . Thank you for your response
im trying to add local multiplayer to my game but ima having problems with the devices joining as one
does anybody know how to fix this
Woke up today and I'm no longer getting button release event data. Are we surprised? Not at all.

Does Parallel.ForEach work in unity? I know there are issues with accessing engine resources on async calls, but are there issues here?
It will work in Unity, potentially subject to limitations on accessing Unity Engine objects from threads that are not the main thread.
Yeah it does seem to have that issue, but the link I posted seems to be Unity's official work around.
the jobs system isn't so muhc a workaround as an officially sanctioned/optimized way to do multithreading in a unity-friendly way
Yeah, I gotta look into it more, I think alot of what I am facing currently could be solved by it.
Anyone know why my WASD keys would stop working after upgrading from 2020.3.4f1 to 2021.3.12f1?
I'm reading the movement input of my player as a Vector2, it's coming back as 0,0 no matter what
All other inputs are working fine though
Hey guys, i have a little issue, whenever i move down my joystick on the gamepad, my character walks by himself to the right, VEEERY SLOWLY, but when i use the keyboard, it stays still, what's going on? i want him to stay still when i press down, but it only works win the keyboard
Any input that's just treated as a button press is working, but anything related to an input axis isn't
Sounds like an issue with deadzones
When you physically move the analog stick down, that's not going to always be a perfect x=0 y=-1 input
There's always going to be a little bit of error both from the way analog sticks work and the way humans work.
You need to ignore any values below a certain threshold and treat them as zero otherwise you'll run into issues like this
how do i set up deadzones?
To be honest I'm not sure, I haven't really done much with gamepads in Unity
But that's just my guess as to what's going on
yeah probably, initially i thought it was an issue with the fact that i added a vertical check variable, but i tried removing every single vertical check and it still SLOWLY walks to the right, so i probably have to set up dead zones
Meanwhile I just can't get my player movement input axis (or literally any other input axis action) to read anything but 0
The only thing I changed is my Unity version
Hmmm setting it to Pass Through fixes it. Weird.
sorry for bothering you, but how do i ignore values below a certain treshold? like, i want my character to move ONLY WHEN the stick is moved in the x axis, if the stick is moved in the y axis i want him to stop
Your movement script will need to check and process the x and y values of the movement input before actually applying them to the player
how do i do that?
That's up to you to figure out, I don't know your code 😛
i can send a screenshot of my movement code if it's not a problem for you
i'm a beginner so there are a lot of things i still have to learn
(heads up that I'm blind and cannot read screenshots)
No I'm being serious, I'm blind
I cannot read without a screen reader
oh, i'm sorry i didn't know
Hehehe turns out my bugs were not mine
Input System 1.4.2 and 1.4.3 are heavily smashed
I reverted to 1.3.0 and all the issues went away
How good is your reader tho
어몽어스 써씨 바카
I need a screen reader to read more than one word per second.
So I'm guessing it can't read foreign languages 😞
Using the new input system, I'm getting opposite mouse scrolls in editor and the linux build (eg 1;-1 vs -1;1)
is there a way to prevent player input manager / the multiplayer input from associating the editor with user 0?
Could be down to your OS preferences
Hi, I am having a issue where unity is getting a input from somewhere and controllers I make keep moving off to the left. I have no idea why I have unplugged all input devices and it still happens. Please any help would be AWESOME!
bluetooth?
I have turned off my pc's bluetooth
getting scrolling seems super unsensitive I need to scroll waaay too much to get any response
Use Debug.Log to print out the raw input data you're getting to get a better understanding of what's happening
I think I figured out the issue. In the Input Manager there is two Horizontal options, one is for joystick and the other for keyboard. It seems that the joystick one is the one returning the false input
Any advice on how to get it to stop doing it
if that's the data you're using, sure. Though I would print some more useful info out too so you know wtf you're looking at:
Debug.Log($"Mouse scroll delta is [{Input.mouseScrollDelta}]");```
you'd have to show your code. I'd rather not guess blindly
wdym
How am I supposed to answer this without seeing the code?
in update
it also depends on what you're doing with this Scroll thing
I wanted to make it like in an rts how you can scroll in and out to zoom
Then what is the issue you're asking about?
this owuld be wrong
it's a delta
here I'll try it and see if its as insensitive as it seems
not an absolute value
Is there a way to make a event based input system and not check foe input.getkey every frame?
yep, the new input system supports event-based input handling
Oh there is? Let me check that out
and ideas how I should handle mouse input in a game where my Physics Tickrate is higher than my Framerate?
i use mouse to control physics and I'm having issues because there are multiple ticks in-between each frame and I'm assuming the mouse input becomes 0 during them
Need to show your code, but basically the gist is always read input in Update and consume it in FixedUpdate
Yeah I’m very used to having an accumulating value in Update that gets consumed and reset in FixedUpdate
But my physics tick rate is 360hz
At 60fps that’s 5 physics ticks for every frame
So I think that gist/concept goes out the window
Right now I’m attempting to reuse the last mouse value and decay it slowly over time which is working alright
But that is obviously very dependent on frame rate and will produce inconsistent mouse movement across devices
my brain isnt working
how do i use the input actions asset without the playerinput asset
It doesn't go out the window it works exactly the same way
But why do you need 360hz physics anyway
It's a golf physics simulation
with a fast swinging club
swinging a club from a rigidbody with 2 connected hinge joints, actually
can you tell me what the value of Input.GetAxis is when called before the next frame update?
I.E does the value remain unchanged until the next frame?
because if so, that concept absolutely goes out the window and it should be trivial to understand why
my only thought is to try to sample/calculate the mouse's acceleration/deceleration and use that to predict/extrapolate the mouse inputs in between now and the next Input frame
the issue is that if your mouse is decelerating, the game continues to process the same input value instead of continuing along that same acceleration which causes extreme inaccuracies
int bindingIndex = playerInput.actions["Move"].GetBindingIndex(InputBinding.MaskByGroup("KeyboardMouse"));
why does bindingIndex doesn't return the index of the composite? It instead returns the first binding in that composite, which is annoying cos I want to check if the binding is a composite.
I want to get the name of all of the inputs in that composite, but it seems so complicated to do. I guess I can shortcut to just setting the index of all the binding manually and never change it but it doesn't feel right T_T.
I guess there's isPartOfComposite so I'll work around it. Seems convoluted...
It feels like it'd be easier to construct the whole PlayerInput from scratch than make it in editor and going backwards to get the name of the inputs.
If this is causing inaccuracies for you then you aren't implementing the "read in update, consume in FixedUpdate" paradigm properly. Emphasis on the consume part. Meaning once you read the data you discard it.
Once you act on it*
Read my reply where I already state how I do that lol
That's legit like day one stuff imo
How do you read data that's not there though?
From your reply it sounds like you're not doing it right
But perhaps it'd be better to show your code
I have stated countless times that my fixedupdate loop runs at a higher frequency than Update
lol
Yes and you don't seem to be understanding what I mean by consuming input
Yes basically.
okay now that we've established that I'm not an idiot...
lol
Do you understand my problem?
FixedUpdate will run the next time and inputAccumulator obviously = 0
because another Update() hasn't been called
I need to have a framerate independent physics simulation
my physics simulation is tied to mouse data
You do
no you're answering a question without enough context
how the mouse data is being used matters lol
I.E in this case mouse data is being used to increase/decrease the velocity of a HingeJoint
and every physics tick that HingeJoint slows down by a small amount
i think my only choice is to try to extrapolate the mouse movement
You could limit how much of the mouse input you want to consume in a given physics update.
Instead of zeroing it out as in your example above
I guess my main issues stems from the value going into an exponential equation and not a linear one
i think that's the best summary
if the equation was linear this isn't a problem
unfortunately missing a frame of mouse data and then adding the delta doesn't get you at the same result
Yeah I'm assuming a linear response to input here. If you estimate your current framerate and do a best effort attempt to spread the input consumption out evenly over the next N FixedUpdates (before the next input frame) maybe it'd be smooth?
Say you do the math and expect 5 physics updates before the next frame, you consume only 1/5th of the accumulated input per FixedUpdate until the next frame comes where you repeat that estimation and re-amortize
If that makes sense
i like that idea tbh
because at a fixed framerate, it's 100% framerate independent i think
as long as the framerate is stable and fixed
Yes if your framerate is steady it should be
that's all I need
Which isn't realistic lol but it should usually be ok
i mean these days most game lock pretty steady
and it's definitely something I can be open about
most shooters deal with this I believe and favor a steady framerate
sorry not most, but something like Overwatch that runs at 120 tick physics
a 60fps player would have this issue
Well try it and let me know how it goes.
Honestly
If this doesn't work
Maybe look into the new input system
It has the option to poll input in FixedUpdate
Maybe that should even be plan A
I was looking at that but unfortunately the actual values just get updated by frame still for mouse
i just tried your idea and liking it so far
seems to produce consistent results across any framerate so far
is there a way I can combine one functionality that return different values depending on button pressed?
or am I cursed to have one for each type of interaction
guess this will do
no those are completely unrelated
i see, my lecture was recommending me Invoke C shar event but i think thats just his preference , since Invoke unity event works just as well and then there is generating C# class which is more flexible.
what method do you think people at an industry or indie developers will use?
people in industry and indie devs use both
I also very much doubt your lecture meant this when they said to use C# events
and if they did
I don't think they understoon what it means
because that is one of the least understood features of the input system - the Invoke C# events mode on PlayerInput
Almost nobody actually knows what it does
and i agree with u 100%
Here's what it actually does:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/api/UnityEngine.InputSystem.PlayerInput.html#UnityEngine_InputSystem_PlayerInput_onActionTriggered
It causes the PlayerInput component to fire this event for any input ^
He went through it and he made it sound like he knows what hes doing but when u go home and try it out it doesn't work as he describes it.
( and 3 other events, for things like OnControlsChanged etc )
yes i had a quick read through this doc
Let me guess he referenced the PlayerInput component and did something like playerInput.actions["AcitonMap/ActionName"].performed += _ => SomeFunction();
in the lecture
yep your lecture does not understand "Invoke C# events" mode 😉
to be clear, you can do this regardless of what mode the PlayerInput component is. What this actually is, is sidestepping the PlayerInput's normal functionality and listening to the actions yourself manually
as a student who spend hours searching about input system. I aggree with u here, it felt wrong when he showed us the code, and I was right lectures are useless >.>
even though there are better ways
thx to u am better off learning C# class for input system and Invoke Unity event
Hey everyone. I've got an issue that drives me crazy atm.
I have a UI with some buttons. When the player opens the UI for the first time, a tutorial notification appears. This notification can be closed by using the submit button on the controller.
When the notification is closed, it sets the button focus back to the last selected button and for some reason - the submit event for this button is triggered - even though the button was not selected when the player pressed the submit button to close the notification.
Is there any solution to this?
Hi, I'm following a tutorial for a gamepad virtual mouse, and it's not pressing buttons correctly. I opened up the input debugger, and it looks like the left button is getting set to 1 and 0 properly, but numClicks isn't increasing, which makes me think that there's a difference between the left button going down and it "clicking" internally.
this is what I have:
private void UpdateMotion()
{
if (_virtualMouse == null || Gamepad.current == null)
{
Debug.Log("Either Mouse or Gamepad is null.");
return;
}
Vector2 deltaValue = Gamepad.current.leftStick.ReadValue();
deltaValue *= cursorSpeed * Time.deltaTime;
Vector2 currentPosition = _virtualMouse.position.ReadValue();
Vector2 newPosition = currentPosition + deltaValue;
newPosition.x = Mathf.Clamp(newPosition.x, 0, Screen.width);
newPosition.y = Mathf.Clamp(newPosition.y, 0, Screen.height);
InputState.Change(_virtualMouse.position, newPosition);
InputState.Change(_virtualMouse.delta, deltaValue);
AnchorCursor(newPosition);
bool pressed = Gamepad.current.aButton.isPressed;
if (_previousMouseState != pressed)
{
Debug.Log("Button Pressed");
_virtualMouse.CopyState<MouseState>(out MouseState mouseState);
mouseState.WithButton(MouseButton.Left, pressed);
InputState.Change(_virtualMouse, mouseState);
_previousMouseState = pressed;
}
}
private void AnchorCursor(Vector2 position)
{
Vector2 anchoredPosition;
RectTransformUtility.ScreenPointToLocalPointInRectangle
(canvas.GetComponent<RectTransform>(), position,
canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : Camera.main,
out anchoredPosition);
cursorTransform.anchoredPosition = anchoredPosition;
}
does anyone know how i can extract the position of the mouse in relation to the playr? im trying to make it so the player has different idle animation frames depending on the angle between the mouse and the player
Subtract the mouse world position from the players world position and then calculate the angle from that.
how do i get the world position of the mouse?
i'm trying to build a sample input system local multiplayer project. my goal is to use two distinct game views, one rendering each player's camera, with a different display specified in editor. this is a good model for my actual platform. in editor, i would like pointer clicks going through display 1 to be attributed to player 0, and pointers in display 2 going to player 1, etc. is there a built in way to do this?
my thought right now is to create a FakeMouse for each player, never associate the editor mouse with a player, and modify which fake mouse device sends the event based on which display the editor mouse device is interacting with
i suspect this already exists though, does it?
paging @austere grotto for some good input system science
There's a multiplayer event system in the input system... somewhere
I never used it
So I don't know the details
how can i copy input event data, cast them, make a small change, and requeue? it's the copy and make a change part that is a bit mysterious
So I have an input actions asset, and i want to retrieve the actions within it
how do i acquire them
Hi, I'm getting these errors when disabling and removing a VirtualMouse. I'm using Input System 1.3. Anyone know where this is coming from/if there's anything to do?
Through the indexer or the FindAction method
Looks like it's from your code that's handling button east on the dual shock
button east is disabling a canvas, and one of the elements on the canvas has an OnDisable() function that de-assigns and removes a virtual mouse
I can post that
but the error is from an input system script
private void OnDisable()
{
_playerInput.user.UnpairDevice(_virtualMouse);
InputSystem.RemoveDevice(_virtualMouse);
InputSystem.onAfterUpdate -= UpdateMotion;
}
Show the full stack trace
lemme see if i can recreate it rq
Basically sounds like you're maybe trying to unpair or remove a device that was already removed or something like that
oh it looks like it's actually an action map issue
this is part 1
that action map absolutely exists this is an issue that's only started popping up with the gamepad cursor implementation
does it think it's an empty action map?
oh yeah this is console pro 3
i can find unity's default
is this better? or are you looking for something else
New input system - seems like they want a InputSystemUIInputModule enabled for UI stuff, but then that completely overrides my active ActionMap and I only get the events from the input module. Is that expected? Is it documented?
Looks like the answer was... disable the InputSystemUIInputModule then re-enable it again, and now I get both events. 😐
Hello. I have a question I would like to move the player (3D) by 1 on a grid using the input system with WASD and arrows. Tips?
So I have my input system all set up and working great. What I'd like to do now is simply detect where the last input came from (determine if it was Mouse and Keyboard OR Gamepad). What is the best way to do this?
Have you got it set up so that you detect the input events yet?
Yes, I am making a capsule move but I would like it to move 1 square instead of always going straight when I move
Do you want it to move instantly, or over time?
move instantly
Okay, so the main thing is to translate the input movement vector into a world space movement vector. That probably just means multiplying it by the tile size. Then just add that to the transform position - no speed, no delta time.
Calling this function when input is made seems to work. Feels messy though. Maybe you all have a better way to handle it?
Why not just store playerInput.currentControlScheme?
🤷♂️ thought it looked nicer in the inspector as an enum rather than an editable string field
Why do you want it in the inspector, if you're setting the value at runtime? Just for visibility?
My targeting system has inputs for press, hold, release and I need that system to know if the input came from Mouse and Keyboard or Gamepad
the system needs to function slightly differently
but yes for debugging and play testing it is nice to be able to see when the scheme has been changed too
I would probably just try and use separate inputs for each one, rather than trying to inspect the scheme separately
Yeah I was just kinda realizing that might be a smarter way 😅
So I'm trying to get the display name of one of my inputs, but it somehow changes between "View" (expected one) and "Select" (the gamepad one, even tho I've set all my input in PS4 and Xbox and none in gamepad). I'm typing this :
Debug.Log(playerInput.actions["OpenSettingsMenu"].GetBindingDisplayString(InputBinding.MaskByGroup("Xbox")));
I think it happens when I use the controller, still I have not idea why it happens, playerInput being the only thing that could change between the debugs and I have only one of those.
Yup, only happens when I'm using the controller, if I switch back to keyboard it goes back to "View" again
when i select another window then unity again while the game is running i get null exception errors every frame
Typical debugging strategies apply
I cant find anything online if thats what you mean (i stupid)
You can't find anything online? It's the most common error in existence
-figure out what's null
- figure out why
- fix it
I started a new indie horror game project with my friend and I'm getting this problem;
I am using an FPS Controller and Unity's character controller asset.
Please let me know if there's a way to code camera movement for playstation 5 input 🙂
(sorry for bad video quality)
Hello!
I am making a mock up of something in Unity for VR, ive followed a beginners setup of an XR system for it and ive gotten to a point where i have hands and (i think) the input system set up... the only problem is i have zero idea how to use it.
There are the L and R hand controllers that have the prefab for the hand models, this prefab contains the model and a particle system along with a controller script called "RegenController". All i need to make, is something that when on either hand, if you pull the main trigger it starts the particle system on the relevant hand, and if BOTH trigger and grip is pulled it runs a different particle system on the same hand.
I can make the activation stuff, i just need to know, basically, how do i use the inputs from the XR stuff on the "RegenController" script
Thanks!
tldr ; basically i just need to know how VR input works for things like the trigger or grip
I'm trying to assign 1 single input action in a script and then check for the input in Update, but for some reason, whenever I press the key I assigned, it doesn't trigger. Here is an example of my code:
public InputAction action;
void Update()
{
if(action.triggered) Debug.Log("Input pressed");
}
It doesn't print the Debug.Log in the console even when I press the button that I assigned in the inspector. Is there something I'm missing?
Hello! This might have already been talked about, but I can't seem to really understand it. I'm trying to have a character rotate depending on gamepad input (vector2). I got the values of this Vector2 and understand what they mean, but I can't seem to have my character rotate using those values. I tried
Vector2 move
public HandleMovement()
{
transform.rotation = Quaternion.Euler(move.x, 0 , move.z);
}
But this only seem to add the 1 and -1 to the rotation of the object which goes up to 180.
I hope this is understandable
You'll have to be more specific about the nature of the rotation you're trying to achieve and how this move vector was created.
You might need action.Enable() in Start()
Hi guys! I have a fully working character with my controller so that's nice. Though, I have 2 different playable characters, and I want to have local multiplayer. Right now, if I have both character prefabs on my screen with different scripts attached (they have different controls but some are the same, like moving with the left pad), they will move together, jump together, etc, from one controller. Like, it isn't split into two controllers. I'm not sure what to do
pls help 😭
Hi!
Does anyone know a good topic about the "Update mode" especially which one to use in different contexts?
For example the dynamic is the default, but some in some cases the fixed one is better?
when do I need the EventSystem object?
I saw that I need it when I'm making buttons that switch scenes
I don't really understand what it says on the documentation
i want it so if shift is pressed, the player speed changes, but how do i get it to change back after i let go of shift?
is there like a method for when the button is no longer pressed?
Yup, that worked. Thanks!
Event system is needed if you want to use anything that involves the event system which includes:
- any interactive UI elements
- any scripts using the Event trigger component
- any scripts using event system listener interfaces for example IPointerEnterHandler, IDragHandler, etc
Yep. Depends on how you're handling input though
Quick question, given an InputAction.CallbackContext, is there any way you can make a device leave and allow them to join back on button press again? I'm making a multiplayer game where players can hop in and out with gamepads with buttons and not by disconnecting the controller, and I've tried InputSystem.DisableDevice( context.control.device ) and InputSystem.RemoveDevice( context.control.device ) and neither seem to let me join back with that device again.
this is how i had the input system methods sorted out
and movement method interprets the moveinput like this
Hello! Sorry for not following up with my message yesterday. I have followed Brackeys Tutorial on a third person controller, but I'm trying to have camera stay on the same position. So the only thing I want is the player forward to be the same as the camera. I also tried to implement moving with a joystick, with the new input system as a pass through vector2. The issue is, I might have missed some things and tweaked the wrong ones, because the character keeps drifing without any input, like it has a constant force being applied to it. Could someone help me review the code?
https://paste.ofcode.org/c5t7cxwmjDRrNnhaNmRaCR
Is there a way to get text-input with the new input system? I imagine marking all keys as actions corresponding to the key and then filtering that into text is a very good idea if there's an in-built system.
Do you have a Sprint action in your input actions?
Send messages takes InputValue not callback context
Yeah just read the input value
If it's 0 it was released
is that a good idea?
it feels very like
band-aid idk
That's the way to do it with Send Messages
ah okay
i could do if else but i heard return is good
how can i change animation speed
is there a way to get the display index of a mouse input event (MouseState)? my goal is to use a single editor mouse to simulate two distinct devices, depending on which display is interacted with in the editor
or maybe is there a way to get the unprocessed position of the mouse pointer (yes) and determine which display editor window it is currently over?
i see this:
public struct MouseState : IInputStateTypeInfo
{
...
// Not currently used, but still needed in this struct for padding,
// as il2cpp does not implement FieldOffset.
[FieldOffset(26)]
ushort displayIndex;
my attempts to read it with
var displayIndexStateBlock = new InputStateBlock
{
byteOffset = 26,
sizeInBits = 16,
bitOffset = 0,
format = editorMouse.clickCount.stateBlock.format
};
var displayIndexControl = new IntegerControl();
displayIndexControl.Setup()
.At(editorMouse,0)
.WithStateBlock(displayIndexStateBlock)
.Finish();
...
var displayIndex = displayIndexControl.ReadValueFromEvent(stateEvent);
are not succeeding
i get nonsense
well it looks like displayIndex is correctly set in the state, it is hard to read but it is there
okay better question: how do i get the MouseState struct from a InputEventPtr for a Mouse??
this is shockingly hard
Hey guys, I’m working on a 2D platformer and I want a good viable movement system using the new input system.
Does anyone have any tutorials or anything?
So I'm having an issue with UI not receiving input events after a game object with the PlayerInput component has been destroyed.
At first I thought it was because the Multiplayer Event System was destroyed, but then I have them in a persistent scene to see if that fixes the issue, but I get the same result.
This issue happens even when switching scenes. And I don't understand what is going on. The PlayerInputManager component doesn't have a destroy player function so I have to do it manually.
I tried getting it to work with a normal Event System and 2 Multiplayer Event System objects just to see if that works and then I tried with just 2 Multiplayer Event System objects, but still nothing works.
If your PlayerInput component is destroyed, there is no input to interact with the UI
That makes sense but if that is the case why does it allow me to process UI events before the PlayerInput component has been added?
If anything I'm probably going to have to add a PlayerInput at the startup of the game and then if I need to add Player 2 just add and remove the second input ass needed.
If you're using multiplayer event system each one is tied to a PlayerInput right?
If you use the normal Event System - it interacts with the input system via the Input Module component
Yes I use it for a character select screen
and that is it
What I thought would happen is if I set the Player Root field to null the Multiplayer Event System would be ignored and the normal Event System would take over input processing, but apparently that isn't the case.
having just done this
- you don't need player input manager
- player input is way too complicated and way too useless for what it is. see https://github.com/AppMana/appmana-unity-plugin/blob/experimental/multiplayer/AppManaPublic/Multiplayer/StreamedPlayer.cs
- finally, you have to implement a subclass of
*Raycasterto make it user-aware, see https://github.com/AppMana/appmana-unity-plugin/blob/experimental/multiplayer/AppManaPublic/Multiplayer/PerUserGraphicRaycaster.cs
you should have an event system & input system ui input module for every user
you're trying to make a local multiplayer game right? with a shared or split screen?
Yes it is a multiplayer game.
Not it is a single screen game.
I'm using Multiplayer Event System oinly for character select.
Not needing the Player Input Manager is kind of weird, but if it will work without it then I guess that is fine.
place all your characters into the scene
then associate the devices
it really depends what game it is
I suppose that would work, but the fact I can't do it the easy way (or what I assume is the easy way) kind of annoys me 😅
so help me understand if it's single screen - how do you want the UI to work?
the player root field is only used for the MoveEvent
that root field will only allow the user to Select via directional navigation the UI elements under that root field.
So when I enter the character select each player should be able to select their character and hit the ready button. And the Ui should update when a player has changed the character.
directional navigation makes sense if it's 4x controllers for example
it's liek a super smash game?
This works for me but when I leave the screen everything breaks.
when you say leave the screen
what do you mean?
it's not an input system issue
it's a scenes issue
you probably do not want to use scenes
Well no I have my character select screen on a separate canvas. that isn't the issue.
The issue only happens when I remove Player Input objects then no UI events are processed
why are you removing the player input objects
what kind of game is it?
I assumed since I wouldn't be using them on lets say something like the Title Screen they should be deleted.
A multiplayer puzzle game like Tetris Attack
well destroying or disabling a PlayerInput disconnects / destroys / disables the user
Also I remove players because there is no reason to have multiple players for a single player mode (At least that is what I would think 😅 )
huh?
when you say single player mode...
you're making a multiplayer game
it's tetris attack. it's 4 people sharing a screen with controllers right?
and each player has his own little column of tetronimos
sure
Yeah but if a player is playing against bots no need for CPU to have a Player Input Object right?
every real living breathing human needs a corresponding PlayerInput if you want to use the local multiplayer components from Input System
so the right answer is not 0
That actually makes sense
What is odd is in my other games (which are single player) I delete/disable the Player Input on Screen which have no gameplay and everything works fine. But in those cases I'm not using Multiplayer Event System
it will be more apparent from input system debugger what is going on
i think what is extremely confusing in the unity editor is that it joins the editor mouse and keyboard to User 0 (i.e. the first player input in the hierarch)
and schemes are an extremely janky way to test multiple users
they expect you to use controllers for local multiplayer games
Which kind of doesn't work if you are also targeting PC. Someone will need/want to use keyboard/mouse
So basically to solve my issue just don't delete/disable Player Input objects and I should be fine because the rest of the system works as intended.
yes
Yeah it does
the multiplayer event system also does very little
it doens't do what it sounds like it should do
Thing is I could probably make my own PlayerInput using the API but using what is there is just far more convenient
Yeah that is true, and also since it inherits from EventSystem I am confused on how we can have multiples, but the base EventSystem class we can only have 1
Hi everyone! in openXR project I develop interacting with the UI InputField I use locks my other inputs (character movements etc) why that might be?
- In build, Input field locks/freezes my character and doesnt read on-screen keyboard inputs
- In editor, everything works perfectly, I can move while I write, also I can write
Hey Everyone, Im having a weird glitch with the input of my character. when using a joy stick and is spin the stick at Max dead zone it stutters, moving the stick (xbox controller) quickly not at max deadzone the movement is smooth
Vector3 move = new Vector3(moveInput.x, 0, moveInput.y);
if (move != Vector3.zero)
{
gameObject.transform.forward = move;
}
controller.Move(move * Time.deltaTime * playerSpeed);
here is a snip of my movement code on update, since i cant post pictures here
and yes the input system is already set to dynamic update
Hey all, any thoughts on why my test fails? If I run them all together MouseRightClickUpdatesNavigation fails because the mouse event seems to not fire. But when I run the test on its own it passes
Here are the tests in question
[UnityTest]
public IEnumerator MouseLeftClickSelectsUnit()
{
var clickDestination = Object.FindObjectOfType<Unit>().transform.position + new Vector3(0, 0.1f, 0);
var clickDestinationScreenPosition = _camera.WorldToScreenPoint(clickDestination);
var mouse = InputSystem.AddDevice<Mouse>();
Set(mouse.position, clickDestinationScreenPosition);
Click(mouse.leftButton);
yield return null;
var selection = Object.FindObjectOfType<PlayerSelection>();
Assert.AreEqual(selection.units.Count, 1);
}
[UnityTest]
public IEnumerator MouseRightClickUpdatesNavigation()
{
var clickDestination = new Vector3(2, 0, 0);
var clickDestinationScreenPosition = _camera.WorldToScreenPoint(clickDestination);
var mouse = InputSystem.AddDevice<Mouse>();
Set(mouse.position, clickDestinationScreenPosition);
Click(mouse.rightButton);
yield return null;
// NOTE(jesse): NavMeshAgent floats above the ground by design, so can't test y
// https://answers.unity.com/questions/1519276/navmesh-is-floating-above-ground.html
var unit = Object.FindObjectOfType<Unit>();
var navMeshAgent = unit.GetComponent<NavMeshAgent>();
Assert.AreApproximatelyEqual(clickDestination.x, navMeshAgent.destination.x);
Assert.AreApproximatelyEqual(clickDestination.z, navMeshAgent.destination.z);
}
How can I detect mouse up? I have this:
With gamepad it works
My script looks like this:
It fires twice when I click it and once when I release it
I have no idea what these things do:
But by looking at the documentation maybe that's how?
Or maybe somewhere in here?
Oh man, you just described the exact problem I posted about on their forum:
https://forum.unity.com/threads/distinguishing-mouse-up-vs-mouse-down-events.1359092/
I have no idea how this system is so bad that such an obvious requirement is not clearly documented
I have a "Click" action of type "Pass Through", Control Type "Button", and Initial State Check is true. I get C# events to my application. If I hook...
I only get 2 events though, not 3 like you, so perhaps you have something else going on as well. Maybe grab the action object which is inside the callback context and print that out, look at its fields, etc
It's kind of impossible to use a debugger for this because then you're changing the input state while it's in the debugger, so this really needs to be documented clearly and properly.
Thank you for sharing
I will take a look, thanks. What do you mean 2 events? one on mouse down and one on mouse up?
I get 2 on mouse down for some reason
Yes, I mean one on down, one on up.
In that case, I think that cs value.ReadValueAsButton() returns false on mouse up and true on mouse down
Ah, that's something at least.
Do you have a InputSystemUIInputModule in the scene? I was finding that it could emit extra events from there, so I'd get one click from "UI/Click" and another from "Player/Select". I can't remember how I fixed that - there was a point where the InputModule was blocking all my Player inputs entirely until I disabled and re-enabled the module and then magically it started working 😐
I did. Even after disabling it I get two
Maybe I have more than one. I can't remember how to search the scene for components. Do you know?
t:ComponentTypeName in the search bar at the top of the Hierarchy
Thanks
Nope, just the one
I did come up with a work-around, but I will have to fix it at some point
Thanks for your help anyway
How can i convert this to the new input system?
private void MyInput()
{
// If auto weapon, allow holding, else, you must click to fire
if(allowButtonHold) shooting = Input.GetButton("Fire1");
else shooting = Input.GetButtonDown("Fire1");
// Reload Input
if(Input.GetKeyDown(KeyCode.R) && bulletsLeft < ammoCount && !reloading) Reload();
//Shoot
if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
{
Debug.Log("Shoot");
bulletsShot = bulletsPerShot;
}
}```
Learn the new system through examples and tutorials first then convert this when you understand it.
Thing is there are many valid ways to use the new system
hello!
i've made a keyboard in VR that works with physics interactions. im now looking to set up each key press triggering the actual GetKeyDown so that it plugs and plays with whatever unity UI system the user wants to plug it into but everything i see has a lot of people saying "you cannot/should not simulate key presses because you can just call the function otherwise" but without simulating from the VR key presses, the keyboard will take some time to integrate into each different UI system
Using the "Send Messages" Behaviour is there a way to assign an event to the "canceled" event listener?
I have InputAction rotateAction = _PlayerInput.actions["Rotate"];
Later on I have
float rotateDirection = rotateAction.ReadValue<float>();
if (rotateDirection != 0)
{
_CinemachineFramingTransposer.m_XDamping = 0;
_CinemachineFramingTransposer.m_YDamping = 0;
_CinemachineFramingTransposer.m_ZDamping = 0;
_CinemachineFramingTransposer.m_DeadZoneWidth = 0;
_CinemachineFramingTransposer.m_DeadZoneHeight = 0;
_CinemachineFramingTransposer.m_SoftZoneWidth = 0;
_CinemachineFramingTransposer.m_SoftZoneHeight = 0;
_GameObjectMap.transform.Rotate(0, rotateDirection * rotateSpeed, 0, Space.Self);
}
else
{
_CinemachineFramingTransposer.m_XDamping = 1;
_CinemachineFramingTransposer.m_YDamping = 1;
_CinemachineFramingTransposer.m_ZDamping = 1;
_CinemachineFramingTransposer.m_DeadZoneWidth = 0.65f;
_CinemachineFramingTransposer.m_DeadZoneHeight = 0.65f;
_CinemachineFramingTransposer.m_SoftZoneWidth = 0.8f;
_CinemachineFramingTransposer.m_SoftZoneHeight = 0.8f;
}
This is inside the Update function. This means that on every frame that else statement is running setting those values which I don't want taking up the extra resources.
I just want to set those values once when the action is canceled.
so something like rotateAction.canceled = ctx => functioncallhere? but that doesn't seem to work.
nevermind figured it out. for anyone else wondering:
rotateAction.canceled += ctx => Test(ctx);
...
void Test(InputAction.CallbackContext ctx)
{
Debug.Log("test");
}
Hello everyone, I'm having a problem when pressing a joystick's trigger, it clicks on the last UI element I clicked. Is there a way to disable this? Thanks in advanced.
how to make action
to works like old GetKeyDown()??
how do i make it so the new input system has things held down?
it only does things once right now
Use Update
Remove the joystick trigger from the submit action defined on your input module component
Many ways... Depends on the style of input handling you're using.
for example?
i don't want to use
Mouse.current.leftButton.wasPressedThisFrame
cause it uses just one button
i want to get whole action
only for one frame
via InvokeUnityEvents
i have on big MonoBehaviour script which it gets input from InputSystem
and it saving it like in bool's or vector2 etc
and from this monobehaviour im taking input to others
and i want to reset those states after end of frame
Hi there, I'm a 3D artist, and I've been using unity for a good few years and have a fairly good understanding of C#
I'm wondering if anyone has been able to make input based events possible even when not focused on the window of a build? Im trying to make a simple little softwares that plays animations on an avatar based on the inputs ive set in the code
If text is entered into an inputfield, the text doesnt change to the second line if the first line is full of characters.
I also increased the size of the inputfield, but it stays the same
This is a #📲┃ui-ux question
Does Unity button have drag and drop or swipe? I have a game that left clicks and right clicks a certain button, but since I'm exporting it on Android, I want to replace the right click with a swipe. Is there a way for this?
Use EventTrigger
What would be the best way to map input keys to a sprite?
I have images for all keyboard and gamepad inputs and would like to render them in e.g. a settings UI based on the active action
I installed Input system, and it does not show. Does anyone know what to do?
also, my compiler does not recognise it
The InputSystem does not seem to work in [UnityTest]s.
[UnityTest]
public IEnumerator C_SelectAndMoveUnit()
{
var mouse = InputSystem.AddDevice<Mouse>();
...
}
None of the events created by mouse are picked up, and the PlayerInput.devices count is 0
Digital normalizer and digital are the same thing?
Anyone experience weird jittering with the new input system? I'm using a basic mouse look script here:
private void CameraControls()
{
lookInput = look.ReadValue<Vector2>();
float mouseX = lookInput.x * cameraSensitivity * Time.deltaTime;
float mouseY = lookInput.y * cameraSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
mainCam.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
transform.Rotate(Vector3.up * mouseX);
}
But every so often, the camera would snap to a random position and jitter for a frame
Multiplying mouse input by deltaTime is incorrect and is responsible for the behavior you're seeing
Hi, can someone help me? I made player controller system in my game and made it so u can control it with PS4 Joystick. Movement works on x axes but wont work on y axes. This is script and Input manager settings.
Ah, thank you
Hey devs
I am having this weird behavior in InputSystem
Feels like Gamepad.current get cached when you connect your controller and when you disconnect it and try to run the game again, the current would still say as if it is connected to the device
What I did is create InputActions, add the maps and in code I would create an instance for these actions.
Is this issue common or did I do something wrong?
You can check the code here if needed:
https://hatebin.com/hgeytmfzvo
Can anyone help whenever I spawn my player using the new input system and using Don't Destroy On Load it dosen't spawn.
It also bugs my wave spawner because on spawn of the player it adds itself to the wave's targets and then it is just null in the list.
Spawning and DDOL are two separate unrelated things.
Sounds like your object is destroying itself
Also this is all completely unrelated to the input system
I thought it was due to thst
Gosh
I been doing my research and it seems like the only way to access the Actions from an Action map without using string is to Generate C# class for that input system.
It does not matter if am using Invoke C sharp event or Invoke unity event.
Am I right?
InputActionReference is an option
Aaa I see thanks, I will try it out
@austere grotto is it ok for u to show me an example of it being used to access the action
how can i use touch input in a similar way that i do mouse input?
got this
and using Mouse.current.position.ReadValue()
theres Touchscreen.current.position.ReadValue() but for some reason my raycasting and stuff is off for that
it sort of works when its in the bottom half
all the coordinates seem the same as with mouse so i dont know where the problem is
ohh nevermind
i forgot to change mouse to touchscreen in a different part of my code
oh but with touch input the if (ctx.cancelled) doesnt run
Hey, is there something like
Keyboard.current.anyKey.wasPressedThisFrame``` but for Gamepad and Mouse?
I want to do a start screen, with "press any key to start" and I want it to be __any__ key. Mouse, gamepad, keyboard, whatever
InputSystem.onActionChange
Anyone know if the new input system allows for multi button inputs (like shift-click)?
It'll be easy to code manually if not, just figured I should check first
I can't seem to find much on joystick gestures. I could swear there was an asset on the Store that made such gestures easy to register, but I can't find it. This is the only link I can find info on it as well, and it's sparse.
https://forum.unity.com/threads/joystick-gestures.115315/
Does anyone know if such an asset still exists? Or, of writing more fleshed out on how I can achieve joystick gestures.
Hi!
We are working on a game where joystick gestures are used to trigger different character animations. A big inspiration for the system is the one...
Hey, bit of an urgent issue here. It seems I can't use eventSystem.SetSelectedGameObject, as EventSystem leaves the last object selected in my menu system selected still.
This menu system is 4 parent objects that get enabled or disabled in the hierarchy and contain UI buttons. An important part of functionality is having controller usability, however, it seems like I can't get it to "select" a button when switching menu tabs.
How do I set what button the EventSystem considers "selected"?
anyone here able to help me with a phone and pc setup for new input system
how do i get a vector from swiping on touchscreen?
SetSelectedGameObject is the way
Hello I have some tile based movement using the MoveTowards function is there an easy way to change this from the arrow keys to a UI Joystick input?
Here is my current code incase that help
public IEnumerator Move(Vector2 moveVec, Action OnMoveOver = null)
{
animator.MoveX = Mathf.Clamp(moveVec.x, -1f, 1f);
animator.MoveY = Mathf.Clamp(moveVec.y, -1f, 1f);
var targetPos = transform.position;
targetPos.x += moveVec.x;
targetPos.y += moveVec.y;
if (!IsPathClear(targetPos))
yield break;
IsMoving = true;
while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
{
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
yield return null;
}
transform.position = targetPos;
IsMoving = false;
OnMoveOver?.Invoke();
}
None of this code is input related whatsoever
Wait it’s not? What does my MoveTowards function do then?
i'm trying to just make the camera draggable with mouse input, but just a simple while (controls.Player.LeftClick.IsPressed()) in my Update() freezes unity
setting a bool while IsPressed and running a function when it's true has the same result
Calculates a position between the current position and the target position given a certain move speed and deltaTime
Yep that's a fairly obvious infinite loop
Sounds like you want if not while
Im very confused then cause in the tutorial I have followed this is how the player moves
Yes this is code for moving the player
It is not code for reading input
Forgive me for being stupid but if thats the case how is unity getting my inputs?
I have no idea since I can't see your project
Presumably in the code that calls this function
I believe that im just calling the coroutine from the update function of the same script
Sounds like a good place to look
Or wherever moveVec gets set
Is there a quick way to search for this in visual studio?
yep right click on moveVec and find all references
I thought as much but the only references it shows are right there in the Move function
go to wherever that funciton is called from
and see what vector is being passed in as an argument
moveVec is a parameter so it's just a local variable in that function
Would that be this Vector2?
public IEnumerator Move(Vector2 moveVec, Action OnMoveOver = null)
no that's the parameter / function declaration
go to the call site
you said it's in Update
Ahhhh I got you now thankyou for your patience
public void HandleUpdate()
{
if (!character.IsMoving)
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");
// remove diagonal movement
if (input.x != 0) input.y = 0;
if (input != Vector2.zero)
{
StartCoroutine(character.Move(input, OnMoveOver));
}
}
character.HandleUpdate();
if (Input.GetKeyDown(KeyCode.Z))
Interact();
}
here?
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Vertical");```
yes this is where your input processing is happening
and unless you've changed some settings, this will handle both joysticks and keyboard automatically
What about UI Joysticks?
If you want to use UI joysticks it's not really supported out of the box in the old input system
the new system has support for them
you'd have to program it all yourself in the old system
Will it require me rewrite a lot of my code if I switched to the new system?
Im not really sure what that entails
a lot? no, just the input handling bits.
It is a big learning curve to use the new system though
especially if you're not a good programmer
Whatever gave you that impression haha, So would you recommend the switch to someone like me or just manually programme the joystick?
Learning the new system is probably easier simply because there's a lot of tutorials for it. You could even look up tutorials for "on screen sticks" which is a UI joystick.
implementing your own on screen joysticks is harder and there won't be as many tutorials/resources on it
{
controls.Player.LeftClick.started += ctx => MouseMove(true);
controls.Player.LeftClick.performed += ctx => MouseMove(false);
}
public void MouseMove(bool performed)
{
Debug.Log(performed);
dragging = performed;
difference = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue()) - cam.transform.position;
}
void Update()
{
pointerOverUI = EventSystem.current.IsPointerOverGameObject();
if (dragging == true)
{
cam.transform.position = cameraOrigin - difference;
}
}```
this was my attempt at it but the debug.log shows true for a super short time then false again
do you get what i'm going for? how would you set this up?
Ok that's what ill do then, Cant thankyou enough for your patience honestly you're a god send.
I would recommend using the tools god gave us (sorry, unity gave us) for handling drag and drop:
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.IBeginDragHandler.html
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.IDragHandler.html
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.IEndDragHandler.html
ooh i didn't think about that bet i'll give that a shot ty
that's only for UI elements it seems, i'm trying to move the worldspace camera
it is not only for UI elements
You can use it for any object with a Collider
i don't have an object with a collider i think? like i'm clicking nothing because i'm trying to move the camera
and it doesn't seem to work when i click a collider either
it works for colliders
you need:
- a collider on the object
- a physics raycaster on your camera (or physics2draycaster if using 2d collider)
- an event system in the scene
i did not have a physics raycaster, added that, still doesn't work
you need all of the things I mentioned
and also a script which implements the interface
i do, already had the others
{
Debug.Log("OnDrag");
cam.transform.position += new Vector3(eventData.delta.x, eventData.delta.y, 0);
}
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("OnPointerDown");
dragOrigin = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
}```
OnBeginDrag and OnEndDrag are implemented
you have the functions - do you have the interface listed in your class declaration?
Player : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IBeginDragHandler, IEndDragHandler, IDragHandler
ok good now show the inspector of the object that has this script on it?
and show your raycaster and your event system
what other components are on the player? I don't see a collider in that screenshot
oh on the object that calls the drag stuff? i thought you meant an object to click on?
objects in the world with colliders
the script which has the IDragHandler needs to have a collider
yes should work
doesn't seem to be calling any debug.logs
are there any other objects / ui elements in the way?
grey is nothing just camera background, tiles are gameworld objects with colliders on them
clicking background or objects doesn't do anything
the tiles have the Player script on them?
no do they need to?
Whatever object you're clicking on needs to have:
- collider2D
- script with IPointerClickHandler or whatever event interface you want (e.g. drag)
oh i misunderstood how it worked, i thought it was like a playerinputs thing you have one of rather than something that needs to be on the object itself
things you have one of are:
- event system
- raycaster
wouldn't that be a bit cumbersome for moving the camera? i'd need that on the background and every clickable thing in the world
if this is for moving the camera just put it on the background
and have your raycaster (graphic or physics, depending on whether the background is UI or game world object) ignore other layers
oh gotcha i'll try that out
sorry yeah I thought it was for dragging the player or a tile or something
gotcha np
which I guess you did say moving the camera before - kinda thought you meant like clicking on the camera and dragging it - which doesn't make sense now that I think about it
drag handler is kinda orthogonal to the input system tbh
it works with either input system
right, i mean would it be easier to do the whole background and drag handling thing or just learn to actually use the input system to detect a held button?
speaking of, would i do .started and .cancelled here instead of .started and .performed?
You could do it with started and cancelled if you want sure
The in drag stuff is honestly probably kinda weird for what you're doing
yeah
Made more sense when I thought you were dragging an object around
yeye
i tried that and it drags the camera for one frame then stops, despite debug.log printing true to the condition
private void Start()
{
controls.Player.LeftClick.started += ctx => MouseMove(true);
controls.Player.LeftClick.canceled += ctx => MouseMove(false);
}
public void MouseMove(bool performed)
{
dragging = performed;
difference = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue()) - cam.transform.position;
}
void Update()
{
Debug.Log(dragging);
if (dragging == true)
{
cam.transform.position = cameraOrigin - difference;
}
}
You should not be calculating difference in the Mouse move function
That's just for detecting the click and release
You need to check mouse delta in Update here
oh bet works now ty a bunch :)
{
if (dragging == true)
{
difference = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue()) - cam.transform.position;
cam.transform.position = cameraOrigin - difference;
}
}
public void MouseMove(bool performed)
{
mouseOrigin = cam.ScreenToWorldPoint(Mouse.current.position.ReadValue());
dragging = performed;
}
would controls.Player.LeftClick.ReadValue<bool>() work instead of the setting of the bool function btw?
and where do i put my * Time.deltaTime and * speed
aand final question, how do i make it not modify the z value? since it's 2d it's making it 0 which makes nothing visible
I don't see any reason to incorporate speed and deltaTime for a mouse drag.
You can set the position to whatever you want. You don't need to accept the z that comes back from ScreenTOWorldPoint
make your own vector
or set that vector's z to whatever you want
or provide a nonzero z in the parameter to ScreenToWorldPoint
how would i do this? seems like the easiest solution
that also involves just making a new vector3
would this work cam.transform.position = new Vector3(cameraOrigin.x - difference.x, cameraOrigin.y - difference.y, -10);
yeah
i'm moving the camera itself
instead of -10 put cam.transform.position.z
I think it's probably better just to set the z afterwards to what you want
what i want is -10 lol that way i can actually see stuff
float camZ;
void Start() {
camZ = transform.position.z;
}
void LateUpdate() {
Vector3 desiredPos = whatever; (all those calculations)
desiredPos.z = camZ;
transform.position = desiredPos;
}```
^ Simplest best way in my opinion, and not subject to floating point arithmetic imprecision etc
gotcha
speaking of all those calculations i think i fucked it up because it does move the camera but at the start moves the camera to where you click, so it doesn't really end up moving at all
Yeah camera drag is actually kinda tricky.
Here's a code snippet from my current project doing mouse drag:
https://hatebin.com/zyzsfrsheg
though in my case I'm doing click and drag in a 3D isometric view
and my plane is a horizontal (XY) plane
my brain is not braining rn
Vector3 desiredPos = new Vector3(difference.x - mouseOrigin.x, difference.y - mouseOrigin.y, -10);
desiredPos.z = cam.transform.position.z;
cam.transform.position = desiredPos;
this? idk
that kind of works except it's reversed and when i click on one spot it moves the camera for no reason
nvm fixed it, had to swap position of origin and difference
OnMouseOver and OnMouseExit is fully working and has been in the editor when playing for ages, but when building the game it doesnt work - anyone know why?
the heirarchy is like this:
Top (Script + RigidBody)
|-> Middle (Empty)
|-> BottomA (Collider)
|-> BottomB (Collider)
there is of course always a chance its a bug elsewhere in the code but just difficult to track down editor / build differences
Hi, I'm having a problem with the new system where my controllers are combining all my inputs. Auto switch is off and I have no idea where to start with fixing it.
without using PlayerInput, how would a script know which user an action is associated with in a local multiplayer game?
how can i see which user is associated with an event in a callback context?
what is the best way to create a script of the form
[SerializeField] public InputActionReference action;
OR using the generated input actions map classes and correctly only respond to "this user's" input?
those are deprecated. use event system
Hi im trying to make my Charakter Run only while Shift is pressed down but I cant find anything online on how to do it this is the code I used for running
With your current setup you could probably just do:
onFoot.Sprint.started += _ => motor.Sprint();
onFoot.Sprint.cancelled += _ => motor.Sprint();
.started callback will call Sprint() the frame the action is pressed.
.cancelled will call Sprint() again when the action is released.
where do I add this code into :c
