- Home /
iphone/ipad Gyro perpendiculat and moving FPC
I am working on a project and i want my FPC to walk in a scene based on gyro input. My problem is that i don't know how to make it work perpendicular to the ground and not parallel.
I am using Input.gyro to look around me and for walking i am using the standard walking script with gyro.gravity as import and a GUI texture to enable/disable walking.
Looking around script is :
function Update () {
if (gyroBool && !fpc.walk) {
var camRot : Quaternion = gyro.attitude * rotFix;
transform.localRotation = camRot;
}
}
Where gyroBool tests if the gyro is available and fpc.walk is checking if the walking arrow wasn't touch.
FPC walk :
function FixedUpdate() {
if (grounded) {
moveDirection = new Vector3 (gyro.gravity.y, 0,gyro.gravity.x);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
} // Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
if (walk){// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
}
function Update() {
if (Input.touchCount > 0){
var touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began && arrow.HitTest(touch.position)){
walk = true;
}
if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){
walk = false;
}
}
}
Any idea on how to make it walk standing ?
Answer by rhose87 · Jan 03, 2012 at 07:39 AM
I solve it by replacing the following line :
moveDirection = new Vector3 (gyro.gravity.y, 0,gyro.gravity.x);
with :
moveDirection = new Vector3 (gyro.gravity.y, 0,gyro.gravity.x+1);
Your answer
Follow this Question
Related Questions
Need to treat the input.gyro as a steering wheel on iPad 1 Answer
Unity modules for iOS? 1 Answer
Best way to create/design modular Player 2 Answers
iPhone Controller Asset 0 Answers