- Home /
Windows 8 touch equivalent for 'Input.GetAxis("Mouse X")'
I'm trying to figure out an equivalent for Input.GetAxis("Mouse X") that will work with a windows 8 touch screen. I've searched everywhere and can't get a clear answer and everything I've tried hasn't worked.
Answer by h8crew · Aug 21, 2013 at 04:20 PM
Solved my own problem, thought I would post the answer here in case others stumble across this.
Set a Vector2 called 'oldMousePos' and another called 'curMousePos'. On update detect if oldMousePos == new Vector2(0,0), if so oldMousePos = curMousePos. Then make a new Vector2 called mouseDif and it should be oldMousePos - curMousePos. So what we have effectively done here is recreated a delta mouse position which works on Windows 8. You can then use these difference values for whatever you need.
hey could you elaborate a tiny bit more please?
i have this
var cur$$anonymous$$ousePos = Input.mousePosition;
var old$$anonymous$$ousePos:Vector2;
if (old$$anonymous$$ousePos == new Vector2(0,0))
{
old$$anonymous$$ousePos = cur$$anonymous$$ousePos;
}
var mouseDif = old$$anonymous$$ousePos - cur$$anonymous$$ousePos;
but im not really getting anything from this
This is in c# but it shouldn't be hard to convert it.
using UnityEngine;
using System.Collections;
public class delta$$anonymous$$ouse$$anonymous$$ovement : $$anonymous$$onoBehaviour {
// Declare empty variables
Vector2 old$$anonymous$$ousePos = Vector2.zero;
Vector2 cur$$anonymous$$ousePos = Vector2.zero;
Vector2 mouseDif = Vector2.zero;
void Update () {
// Get the current mouse position
cur$$anonymous$$ousePos = Input.mousePosition;
// If this is the 1st time this update has run, set the old mouse position to be the same as the current positon
// This avoids 1 frame of potential jumping on start
if (old$$anonymous$$ousePos == Vector2.zero)
{
old$$anonymous$$ousePos = Input.mousePosition;
}
// Get the difference between the last frame's position and this frame's position
// This is your delta
mouseDif = old$$anonymous$$ousePos - cur$$anonymous$$ousePos;
// Set the old$$anonymous$$ousePos to the current value for use in the next frame
old$$anonymous$$ousePos = Input.mousePosition;
}
}
thanks so much for the quick response! ill look it over
Answer by Peter G · Aug 21, 2013 at 03:52 PM
I haven't ever developed for the windows 8 touch screen so I don't know if it works with Input.GetTouch()
, but if it does, then you should be able to do:
var touch = Input.GetTouch(0);
var deltaX = touch.deltaPosition.x;
Unfortunately unity doesn't detect windows 8 touch by default like that. I did however come up with an easy solution, posting it as answer below.
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
[SOLVED] Input.GetAxis("Horizontal") returns wrong value? -1 Answers
How do I use an Xbox controller axis other than the left thumbstick? 0 Answers
How to get ScrollWheel values using a laptop touchpad? 1 Answer
Achieve framerate independent AddTorque rotaion with mouse drag. 2 Answers