GLFW Mouse doesnt work on Ubuntu+Unity - mouse

I have small problem with mouse in glfw ;/. Its working on Windows and Ubuntu+Gnome3, but it doesnt work on Ubuntu+Unity.
Code for my mouse ( im using it to rotating camera in my game ) :
glfwDisable(GLFW_MOUSE_CURSOR);
int xpos, ypos;
int w,h;
glfwGetMousePos(&xpos, &ypos); // im calculating rot of camera with these values
glfwGetWindowSize(&w,&h); // set mouse
glfwSetMousePos(w/2, h/2); // to center of window.
And it just doesnt work, but when i set glfwEnable(GLFW_MOUSE_CURSOR); it's working but then mouse is visible ;/ what should i do?

[SOLVED]
i dont know why, but when i enabled VSYNC in graphics card settings, mouse is working well o.o?
[/SOLVED]

Related

Unity 2D, get joystick direction

im making a mobile game, the player have a grappling hook and can fly with it (just like spider man), i use some script so the grappling hook is work base on mouse position, but the problem is i want to convert it to mobile game, i can just use leave it as is since click on touch is same as mouse click, but i want to use joystick to get direction. i want make it the same as the fanny mechanism in a mobile legend game, (if you know the game)
i use this script for targeting
on pc (which is fine)
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Vector2 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
rope.setTarget(worldPos); // hook script will get this value
}
i try use this for mobile (the problem):
if (Input.GetKeyDown(KeyCode.Mouse0))
{
float inputX = joystick.Horizontal;
float inputY = joystick.Vertical;
Vector2 dir = new Vector2(inputX, inputY);
rope.setTarget(dir); // hook script will get this value
}
If you want to capture a joystick, it can be achieved through the Input Manager GetAxis function, which can read a Joystick, Mouse or Keyboard arrows/asdw, according to how you configure it.
In code, you would use:
float inputX = Input.GetAxis("Horizontal");
float inputY = Input.GetAxis("Vertical");
If you don't want to have the mouse to look, just configure it in Edit > Project Settings > Input > Axes. There are two "Horizontal" and two "Vertical" configurations. Let exist only that with Joystick configuration and delete the other. Below, it is the image of the axis configured for joysticks:
For more information, check https://docs.unity3d.com/Manual/class-InputManager.html. I hope that helps you to get started!
EDIT: Virtual/screen joysticks on mobile
In the case you are talking about virtual/screen joysticks, you must control it manually, in the hard way. To develop this kind of joystick, you will use the Input Manager to get the mouse/touch position during press (Input.GetMouseButtonDown(int)), release (Input.GetMouseButtonUp(int)) and drag (Input.GetMouseButton(int)). Then you control how much the mouse has moved since the user began to press it and clamp the position to not overflow the joystick area.
As you have stated in comments, you have downloaded an asset from Asset Store. The way the assets work are unique and it is up to their developers to tell how you should use them. Seek for documentation, tutorials and examples given by the developer to see how the asset is intended to be used.

Why does the scene camera change position and rotation on play

Win 10 Pro, Unity 2019.2.17f1
This issue occurs on occasion, randomly. It has happened with multiple different scenes on this machine.
In this instance, I have a scene that is completely empty except for the default Main Camera and Directional Light. I have not added any scripts to the scene. In the inspector the camera is at position 0, 10, 0 with rotation 90, 0, 0 by default. Once I hit play, the camera instantly jumps to a seemingly random position and rotation. If I delete the main camera and make a new camera game object, the same thing happens to it. Please see this screen recording demonstrating the problem:
https://youtu.be/JMl2arXzeCo
I'm thinking it might have something to do with the fact that I have SteamVR running on my machine. Does anyone know what causes this, and where I might be able to find a setting to toggle this behavior? Thank you
In the console you get
OpenVR Initilaized
You seem to have Virtual Reality Support enabled in the ProjectSettings -> Player -> XR Settings thus the camera position and orientation is controlled by a virtual reality device.
From the orientation I would guess that it lies around somewhere ^^
Simply disabling this should fix your issues.
To add to derHugo's answer: to stop the camera from following the VR device without disabling VR support, set the Camera component's Target Eye property to None (Main Display).

Unity - I cant see my mouse on screen

I have made a simple 3D game in Unity and for the most part everything works, but when my player dies the mouse is not visible on the death screen.
I have two other scenes with what looks like to me the same exact settings, yet the mouse on those is visible.
Try to check your script. search for Cursor.visible
https://docs.unity3d.com/ScriptReference/Cursor-visible.html

Detecting a Tilt event on google cardboard not working

I'm trying to go back from one screen to another using Application.LoadLevel(0)
when the user tilts his head with the cardboard.
if(Cardboard.SDK.Tilted)
//do whatever
However Cardboard.SDK.Tilted is always false when I tilt the device in the unity editor using the mouse or when I build and run the app. Any idea why?
Okay so turns out it was working. Just in case someone reads this, in Unity if u press control then move the mouse it will Tilt but it won't trigger the event as Tilted. To do that you have to press the Escape key and it will simulate a tilt event.

unity camera should rotate around static point

When I press the play button for preview, I want the camera to stay static (rotating around a static point) instread of moving around that point in a fixed radius.
I can't find the correct configuration - does anybody know the setting I have to do?
Create a camera object in unity editor (make sure there is only one camera at that depth level).
1.1. If you are using a different camera as well, then delete the audio listener component on the new camera.
Add MouseLook component to your camera (the script comes as default in unity).
2.2 If you cannot find the MouseLook script component, then go to Assets->Import Package -> Characters, and select MouseLook.
Your done, now when you press play you will be able to rotate around with your mouse, but the camera position will be static.