- Home /
Question by
G_Sacristan · May 27, 2011 at 03:37 PM ·
movementiosaccelerometer
move gameObject on z dependently on iOS device movement on x axis...
move gameObject on z dependently on iOS device movement on x axis...
ive got some results, but they are not working how i want them to if im moving device on x axis, but if im rotating its working, but the problem is that i want it to work without rotating
Could someone help me out?
Code:
#pragma strict
var speed = 2;
var toolScr:_ButtonOldCheck;
static var canMoveForward:boolean=true;
static var canMoveBackward:boolean=true;
var moveTreshold: float=0.1;
private var xAcc: float=0.0;
function Start()
{
canMoveForward=true;
canMoveBackward=true;
}
function Update ()
{
var currTool:String=toolScr.oldObj.name;
var dir : Vector3 = Vector3.zero;
if(currTool=="tool1")
{
xAcc=Input.acceleration.x;
print("reading "+xAcc);
if(canMoveForward&&canMoveBackward) MoveObject();
if(!canMoveForward &&xAcc<0&&Mathf.Abs(xAcc)>moveTreshold) MoveObject();
if(!canMoveBackward&&xAcc>0&&Mathf.Abs(xAcc)>moveTreshold) MoveObject();
}
}
function MoveObject()
{
var dir : Vector3 = Vector3.zero;
dir.z = Input.acceleration.x;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate (dir * speed);
}
Comment
Answer by willgoldstone · May 27, 2011 at 03:57 PM
Have you tried manually constraining? either with code or if its a rigidbody - use the constraints checkboxes on the component itself?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
iOS Compass over Unity Remote 5 0 Answers
Move horizontally on touch 0 Answers
How to move player by accelerometer 0 Answers