- Home /
Disable diagonal movement in 3D
I wish to disable diagonal movement of my character in device, I am using something like the below mentioned code for movement.
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y;
dir.z = Input.acceleration.x;
$$anonymous$$aybe just use a simple double IF statement?
if(Input.acceleration.y != 0)
{
dir.x = -Input.acceleration.y;
}
else if(Input.acceleration.x != 0)
{
dir.z = Input.acceleration.x;
}
This way they can only move in dir.z if they aren't triggering dir.x. So only one of those can be happening at a time.
How can move the gameobject to larger angle.
I don't quite understand what you're asking. Could you explain further? Also, have you tried $$anonymous$$elly$$anonymous$$'s answer? It's better than $$anonymous$$e.
thanks for help.i am facing one problem with Input.acceleration. if i rotated the camera in y axis in runtime then my Input.acceleration work opposite direction.how can $$anonymous$$ove the Object to Camera respective.
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y;
dir.z = Input.acceleration.x;
Answer by KellyThomas · Jan 19, 2014 at 02:59 PM
if(Mathf.Abs(dir.x) > Mathf.Abs(dir.z)) {
dir.z = 0;
}
else {
dir.x = 0;
}
Just zero the smaller input.
thanks for help.i am facing one problem with Input.acceleration. if i rotated the camera in y axis in runtime then my Input.acceleration work opposite direction.how can $$anonymous$$ove the Object to Camera respective.
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y;
dir.z = Input.acceleration.x;
$$anonymous$$apping 2D input to 3D space with a variable reference point is a different question.
I recommend asking a new question and giving a lot of information on what is happening in your scene and the type of gameplay you want to support.