public void setPlayer() { GameObject[] pList = GameObject.FindGameObjectsWithTag("Player"); if (pList.Length > 0) { player = pList[0]; body = player.GetComponent <Rigidbody>(); movementStarted = false; playerMoviment = MOVIMENT.IDLE; } }
private void oneFingerTransformHandler(object sender, EventArgs e) { Vector3 currentSwipe = OneFingerMoveGesture.DeltaPosition; Vector2 swipeDirection; //swipe upwards if (currentSwipe.x > 0 && currentSwipe.y < 0) { swipeDirection = new Vector2(1, 0); } else if (currentSwipe.x < 0 && currentSwipe.y > 0) { swipeDirection = new Vector2(-1, 0); } else if (currentSwipe.x > 0 && currentSwipe.y > 0) { swipeDirection = new Vector2(0, 1); } else { swipeDirection = new Vector2(0, -1); } direction = new Vector3(swipeDirection.x, 0, swipeDirection.y); Vector3 movement = direction * Speed; if (playerMoviment == MOVIMENT.IDLE) { movementStarted = true; playerMoviment = MOVIMENT.MOVING; } if (movementStarted && body) { Debug.Log(movement + " " + Speed); // body.AddForce(movement,ForceMode.Impulse); body.transform.position += movement; Quaternion rotation = Quaternion.LookRotation(direction, Vector3.up); body.transform.rotation = rotation; movementStarted = false; } }
void FixedUpdate() { if (!body) { setPlayer(); } else { if (body.velocity.magnitude == 0) { playerMoviment = MOVIMENT.IDLE; } if (!isGrounded && body.velocity.y < 0 && directionJump) { Vector3 directionJumpForce = direction * 2; body.AddForce(directionJumpForce, ForceMode.Impulse); directionJump = false; } } }