public void InitQuery () { speed = 0.0f; nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_IDLE; previousFlyingState = nowFlyingState; QueryObject.GetComponent<QueryAnimationController>().ChangeAnimation(QueryAnimationController.QueryChanAnimationType.FLY_IDLE); }
// Called by touch assistants public void updateiOSMove(float strafe, float forward) { // Animation based on strafe values if (strafe > 0) nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TORIGHT; else if (strafe < 0) nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TOLEFT; else nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_STRAIGHT; // Normalize and factor move speed and delta time Vector3 strafeVec = transform.right*strafe; strafeVec *= moveSpeed*Time.deltaTime; Vector3 forwardVec = transform.forward*forward; forwardVec.y = 0; forwardVec *= moveSpeed*Time.deltaTime; // Dampen the vectors so you don't move so fast strafeVec /= 10f; forwardVec /= 10f; // Take average of 2 vectors Vector3 moveDirection = (strafeVec + forwardVec) / 2f; // Move Forward controller.Move (moveDirection); // Idle if not moving or moving straight backwards moveDirection.Normalize(); if (moveDirection == Vector3.zero || moveDirection == -this.transform.forward) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_IDLE; } // Change flight animation if (previousFlyingState != nowFlyingState) { QueryObject.GetComponent<QueryAnimationController>().ChangeAnimation(nowFlyingState); } previousFlyingState = nowFlyingState; }
void ChangeAnimation(QueryAnimationController.QueryChanAnimationType animNumber) { gameObject.GetComponent <QueryAnimationController>().ChangeAnimation(animNumber); }
void updateMove() { CharacterController controller = GetComponent<CharacterController>(); // Rotate Right or Left if (Input.GetAxis("Horizontal") != 0) { transform.Rotate(0, Input.GetAxis("Horizontal") * ROTATE_SPEED, 0); if (Input.GetAxis("Horizontal") > 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TORIGHT; } else if (Input.GetAxis("Horizontal") < 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TOLEFT; } } else { this.transform.localEulerAngles = new Vector3(0, this.transform.localEulerAngles.y, 0); nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_STRAIGHT; } // Rotate Up or Down if (Input.GetAxis("Vertical") != 0) { transform.Translate(Vector3.up * Input.GetAxis("Vertical") * ROTATE_SPEED * Time.deltaTime); if (Input.GetAxis("Vertical") > 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_UP; } else if (Input.GetAxis("Vertical") < 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_DOWN; } if (this.transform.localPosition.y < groundCollider.transform.localPosition.y) { this.transform.localPosition = new Vector3 (this.transform.localPosition.x, groundCollider.transform.localPosition.y, this.transform.localPosition.z); } } // Move Forward Vector3 forwardSpeed = transform.TransformDirection(Vector3.forward * Time.deltaTime * speed); controller.Move (forwardSpeed); // Speed Control if (Input.GetKey("x")) { speed += ACCELERATE * Time.deltaTime; if (speed > MAX_SPEED) { speed = MAX_SPEED; } } else if (Input.GetKey("z")) { speed -= DECELERATE * Time.deltaTime; if (speed < 0.0f) { speed = 0.0f; } } if (speed == 0.0f) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_IDLE; } // ChangeAnimation if (previousFlyingState != nowFlyingState) { QueryObject.GetComponent<QueryAnimationController>().ChangeAnimation(nowFlyingState); } previousFlyingState = nowFlyingState; }
void updatePCMove() { Vector3 moveDirection = Vector3.zero; Vector3 strafe = Vector3.zero; Vector3 forward = Vector3.zero; // Strafe left/right if (Input.GetAxis ("Horizontal") > 0) { strafe = this.transform.right * moveSpeed; nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TORIGHT; } else if (Input.GetAxis("Horizontal") < 0) { strafe = -this.transform.right * moveSpeed; nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TOLEFT; } else nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_STRAIGHT; // Move forward/backward if (Input.GetAxis("Vertical") > 0) { forward = this.transform.forward * moveSpeed; } else if (Input.GetAxis("Vertical") < 0) { forward = -this.transform.forward * moveSpeed; } strafe *= 10f; forward *= 10f; // Take average of 2 vectors moveDirection = (strafe + forward) / 2f; // Move Forward controller.Move (moveDirection*Time.deltaTime); // Idle if not moving or moving straight backwards moveDirection.Normalize(); if (moveDirection == Vector3.zero || moveDirection == -this.transform.forward) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_IDLE; } // Change flight animation if (previousFlyingState != nowFlyingState) { QueryObject.GetComponent<QueryAnimationController>().ChangeAnimation(nowFlyingState); } previousFlyingState = nowFlyingState; }
void Start() { canMove = true; vertRote = horizRote = gravity = 0; controller = GetComponent<CharacterController>(); // Set initial state/animation nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_IDLE; previousFlyingState = nowFlyingState; QueryObject.GetComponent<QueryAnimationController>() .ChangeAnimation(QueryAnimationController.QueryChanAnimationType.FLY_IDLE); // Spawn touch assistants GameObject go = Instantiate (touchAssistantFab, Vector3.zero, Quaternion.identity) as GameObject; touchAssistant1 = go.GetComponent<TouchAssistant> (); touchAssistant1.playerControl = this.GetComponent<PlayerController>(); touchAssistant1.playerMover = this; go = Instantiate (touchAssistantFab, Vector3.zero, Quaternion.identity) as GameObject; touchAssistant2 = go.GetComponent<TouchAssistant> (); touchAssistant2.playerControl = this.GetComponent<PlayerController>(); touchAssistant2.playerMover = this; }
void updateMove() { CharacterController controller = GetComponent <CharacterController>(); // Rotate Right or Left if (Input.GetAxis("Horizontal") != 0) { transform.Rotate(0, Input.GetAxis("Horizontal") * ROTATE_SPEED, 0); if (Input.GetAxis("Horizontal") > 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TORIGHT; } else if (Input.GetAxis("Horizontal") < 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_TOLEFT; } } else { this.transform.localEulerAngles = new Vector3(0, this.transform.localEulerAngles.y, 0); nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_STRAIGHT; } // Rotate Up or Down if (Input.GetAxis("Vertical") != 0) { //transform.Translate(Vector3.up * Input.GetAxis("Vertical") * ROTATE_SPEED * Time.deltaTime); modif if (Input.GetAxis("Vertical") > 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_UP; } else if (Input.GetAxis("Vertical") < 0) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_DOWN; } if (this.transform.localPosition.y < groundCollider.transform.localPosition.y) { this.transform.localPosition = new Vector3(this.transform.localPosition.x, groundCollider.transform.localPosition.y, this.transform.localPosition.z); } } transform.Translate(Vector3.forward * speed * Time.deltaTime);// modif // Move Forward /*Vector3 forwardSpeed = transform.TransformDirection(Vector3.forward * Time.deltaTime *speed); modif * controller.Move (forwardSpeed);*/ // Speed Control if (Input.GetKey("z")) { speed += ACCELERATE * Time.deltaTime; if (speed > MAX_SPEED) { speed = MAX_SPEED; } } else if (Input.GetKey("s")) { speed -= DECELERATE * Time.deltaTime; if (speed < 0.0f) { speed = 0.0f; } } if (speed == 0.0f) { nowFlyingState = QueryAnimationController.QueryChanAnimationType.FLY_IDLE; } // ChangeAnimation if (previousFlyingState != nowFlyingState) { QueryObject.GetComponent <QueryAnimationController>().ChangeAnimation(nowFlyingState); } previousFlyingState = nowFlyingState; }