C
C#2y ago
Elmishh

❔ how do I get mouse and keyboard input in a vr game BepInEx plugin?

title
24 Replies
Elmishh
ElmishhOP2y ago
gorilla tag to be specific
Doombox
Doombox2y ago
Depends on what input system the game is using you can use Keyboard.current etc.
Elmishh
ElmishhOP2y ago
? the game is in vr it only uses vr inputs
Doombox
Doombox2y ago
you said mouse and keyboard input
Elmishh
ElmishhOP2y ago
yes
Doombox
Doombox2y ago
which can be done with Keyboard.current on the new and Input.GetKeyDown on the old inputsystem one of those will work regardless of VR
Elmishh
ElmishhOP2y ago
and what about mouse movement like left, right, up and down
Doombox
Doombox2y ago
Mouse.current.postiion/delta axis in the new inputsystem or Input.GetMouseAxis or whatever it was called, my memory on it is a bit vague this is all assuming it's a Unity game of course, but you're using BepInEx and it's a VR game so that's a safe assumption
Elmishh
ElmishhOP2y ago
its a unity game yes what would that get? i want the movement of the mouse so if it goes down itll increase and if its still itll go back to 0
Doombox
Doombox2y ago
https://docs.unity3d.com/ScriptReference/Input-mousePosition.html you'll have to track the position manually per-frame the old input system doesn't support per frame mouse delta i don't think
Elmishh
ElmishhOP2y ago
if i do mousePosition - prevMousePosition would that work?
Doombox
Doombox2y ago
yup if the game is using the new inputsystem though it's a lot easier that will give you deltas out of the box
Elmishh
ElmishhOP2y ago
what is the new input system i dont even know what a delta is...
Doombox
Doombox2y ago
a delta is a change in something so a mouse position delta would be how much the mouse position has changed
Elmishh
ElmishhOP2y ago
few minutes ill make something rq to test how it works
Elmishh
ElmishhOP2y ago
using BepInEx;
using System;
using UnityEngine;
using Utilla;

namespace GorillaFPV
{
/// <summary>
/// This is your mod's main class.
/// </summary>

/* This attribute tells Utilla to look for [ModdedGameJoin] and [ModdedGameLeave] */
[ModdedGamemode]
[BepInDependency("org.legoandmars.gorillatag.utilla", "1.5.0")]
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
Vector3 resetPosition;
float mouseMovementY;

GameObject cube;
void Setup()
{
GameObject placeHolderCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
placeHolderCube.transform.localScale = Vector3.one * 0.08f;

cube = Instantiate(placeHolderCube);
cube.GetComponent<Collider>().enabled = false;
}
void Start() { Utilla.Events.GameInitialized += OnGameInitialized; }

void OnEnable()
{
HarmonyPatches.ApplyHarmonyPatches();
}

void OnDisable()
{
HarmonyPatches.RemoveHarmonyPatches();
}

void OnGameInitialized(object sender, EventArgs e)
{
Setup();
cube.transform.position = GorillaLocomotion.Player.Instance.rightHandFollower.position;
}

void Update()
{
mouseMovementY = Input.mousePosition.y;
cube.transform.position = Vector3.up * mouseMovementY;
}
}
}
using BepInEx;
using System;
using UnityEngine;
using Utilla;

namespace GorillaFPV
{
/// <summary>
/// This is your mod's main class.
/// </summary>

/* This attribute tells Utilla to look for [ModdedGameJoin] and [ModdedGameLeave] */
[ModdedGamemode]
[BepInDependency("org.legoandmars.gorillatag.utilla", "1.5.0")]
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
Vector3 resetPosition;
float mouseMovementY;

GameObject cube;
void Setup()
{
GameObject placeHolderCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
placeHolderCube.transform.localScale = Vector3.one * 0.08f;

cube = Instantiate(placeHolderCube);
cube.GetComponent<Collider>().enabled = false;
}
void Start() { Utilla.Events.GameInitialized += OnGameInitialized; }

void OnEnable()
{
HarmonyPatches.ApplyHarmonyPatches();
}

void OnDisable()
{
HarmonyPatches.RemoveHarmonyPatches();
}

void OnGameInitialized(object sender, EventArgs e)
{
Setup();
cube.transform.position = GorillaLocomotion.Player.Instance.rightHandFollower.position;
}

void Update()
{
mouseMovementY = Input.mousePosition.y;
cube.transform.position = Vector3.up * mouseMovementY;
}
}
}
Elmishh
ElmishhOP2y ago
help... it used the old one -_- uses
Doombox
Doombox2y ago
uses the new one actually Input.mousePosition is the old system https://docs.unity3d.com/Packages/[email protected]/manual/index.html these are the full docs for it but it doesn't really cover how to use it like you're trying to what you want is Mouse.current. and the properties it has https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.InputSystem.Mouse.html delta will be the change since the last frame, and position will be the current position in pixel coords so in full var pos = Mouse.current.position.ReadValue<Vector2>();
Elmishh
ElmishhOP2y ago
The non-generic method 'InputControl<Vector2>.ReadValue()' cannot be used with type arguments is what i get when i do that
mouseMovementY = Mouse.current.position.ReadValue<Vector2>().y;
mouseMovementY = Mouse.current.position.ReadValue<Vector2>().y;
Doombox
Doombox2y ago
oh yeah just remove <Vector2> memory failed me a bit there
Elmishh
ElmishhOP2y ago
already tried that tho oh wait nvm i removed JUST Vector2 and left the <> lemme test it
Elmishh
ElmishhOP2y ago
this is just SPAMMED all over the bepinex console code:
using BepInEx;
using System;
using Technie.PhysicsCreator;
using UnityEngine;
using UnityEngine.InputSystem;
using Utilla;

namespace GorillaFPV
{
/// <summary>
/// This is your mod's main class.
/// </summary>

/* This attribute tells Utilla to look for [ModdedGameJoin] and [ModdedGameLeave] */
[ModdedGamemode]
[BepInDependency("org.legoandmars.gorillatag.utilla", "1.5.0")]
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
Vector3 resetPosition;
float mouseMovementY;

GameObject cube;
void Setup()
{
GameObject placeHolderCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
placeHolderCube.transform.localScale = Vector3.one * 0.08f;

cube = Instantiate(placeHolderCube);
cube.GetComponent<Collider>().enabled = false;
}
void Start() { Utilla.Events.GameInitialized += OnGameInitialized; }

void OnEnable()
{
HarmonyPatches.ApplyHarmonyPatches();
}

void OnDisable()
{
HarmonyPatches.RemoveHarmonyPatches();
}

void OnGameInitialized(object sender, EventArgs e)
{
Setup();
cube.transform.position = GorillaLocomotion.Player.Instance.rightHandFollower.position;
}

void FixedUpdate()
{
mouseMovementY = Mouse.current.position.ReadValue().y;
cube.transform.position = Vector3.up * mouseMovementY;
Debug.Log($"[gorillaRPV] PositionDebug[cube]: {cube.transform.position}");
Debug.Log($"[gorillaRPV] PositionDebug[mouse]: {mouseMovementY}");
}
}
}
using BepInEx;
using System;
using Technie.PhysicsCreator;
using UnityEngine;
using UnityEngine.InputSystem;
using Utilla;

namespace GorillaFPV
{
/// <summary>
/// This is your mod's main class.
/// </summary>

/* This attribute tells Utilla to look for [ModdedGameJoin] and [ModdedGameLeave] */
[ModdedGamemode]
[BepInDependency("org.legoandmars.gorillatag.utilla", "1.5.0")]
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
Vector3 resetPosition;
float mouseMovementY;

GameObject cube;
void Setup()
{
GameObject placeHolderCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
placeHolderCube.transform.localScale = Vector3.one * 0.08f;

cube = Instantiate(placeHolderCube);
cube.GetComponent<Collider>().enabled = false;
}
void Start() { Utilla.Events.GameInitialized += OnGameInitialized; }

void OnEnable()
{
HarmonyPatches.ApplyHarmonyPatches();
}

void OnDisable()
{
HarmonyPatches.RemoveHarmonyPatches();
}

void OnGameInitialized(object sender, EventArgs e)
{
Setup();
cube.transform.position = GorillaLocomotion.Player.Instance.rightHandFollower.position;
}

void FixedUpdate()
{
mouseMovementY = Mouse.current.position.ReadValue().y;
cube.transform.position = Vector3.up * mouseMovementY;
Debug.Log($"[gorillaRPV] PositionDebug[cube]: {cube.transform.position}");
Debug.Log($"[gorillaRPV] PositionDebug[mouse]: {mouseMovementY}");
}
}
}
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server