- Home /
Charecter controlled by accelaration for iphone..
Hello Friends,
i have to know the charecter controller by acceleration, actually i want that the charecter position in between ranges,accelaration controlled to charecter,,,..here charecter as no ridigbody...please reply about his......
Any Example is there for charecter comtrol by accleration .......charecter moves left and right by accelratuion..
once check please i tried some..
using UnityEngine; using System.Collections;
public class example : MonoBehaviour
{ public float speed = 10.0F;
void Update()
{ Vector3 dir = Vector3.zero;
dir.x = Input.acceleration.y;
// dir.z = Input.acceleration.x;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir.x = dir.x * Time.deltaTime ;
Debug.Log(dir.x);
//if(dir.x < -0.8f || dir.x > 0.8f)
if(transform.position.x <= -0.8f || transform.position.x >=0.8f)
transform.Translate(dir.x * speed,0,0);
// dir *= Time.deltaTime;
//transform.Translate(dir * speed);
}
}
Thanks,
Sorry for my poor English..........
Your answer
Follow this Question
Related Questions
resolutions 1 Answer
About ListItems in Unity3D 1 Answer
How to create button for jumping in unity3d for iphone 1 Answer
How To Crop the Gallery image for iphone in unity3d 0 Answers
how to use specific touch in unity for iphone and ipod 1 Answer