public void SwipeDetect() { Direction = swipeDirection.None; if (Input.GetMouseButtonDown(0) && initialSet == false) { initialPosition = Input.mousePosition; initialSet = true; } if (initialSet == true) { delta = initialPosition - Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y)) { if (Mathf.Abs(delta.x) > ThX) { Direction |= (delta.x > 0) ? swipeDirection.Left : swipeDirection.Right; } } else { if (Mathf.Abs(delta.y) > ThY) { Direction |= (delta.y > 0) ? swipeDirection.Down : swipeDirection.Up; } } initialSet = false; delta = new Vector3(0, 0, 0); } }
void Update() { Direction = swipeDirection.None; if (Input.GetMouseButtonDown(0)) { touchPosition = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { Vector2 deltaSwipe = touchPosition - Input.mousePosition; if (Mathf.Abs(deltaSwipe.x) > swipeResistanceX) { //Swipe on the x Direction |= (deltaSwipe.x < 0) ? swipeDirection.Right : swipeDirection.Left; } if (Mathf.Abs(deltaSwipe.y) > swipeResistanceY) { //Swipe on the y Direction |= (deltaSwipe.y < 0) ? swipeDirection.Up : swipeDirection.Down; } } }
// to be used by other script to emulate turning 180 on same path direction public void swipped(swipeDirection sDir) { switch (sDir) { case swipeDirection.Up: if (pathScript.currDir == plaerFollowingPath.currDirection.Down) // && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theUpWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theUpWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Up; } } break; case swipeDirection.Down: if (pathScript.currDir == plaerFollowingPath.currDirection.Up) // && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theDownWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theDownWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Down; } } break; case swipeDirection.Right: if (pathScript.currDir == plaerFollowingPath.currDirection.Left) // && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theRightWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theRightWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Right; } } break; case swipeDirection.Left: if (pathScript.currDir == plaerFollowingPath.currDirection.Right) // && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theLeftWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theLeftWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Left; } } break; } }
new public void Update() { base.Update(); //Debug.Log(dataMana.nbrDaction + " nbrDaction || " + positionList.Count + " positionList.Count || " /*+ actionType + " actionType"*/); // LE DEBUGGER /*if (Input.GetKeyDown(KeyCode.Space)) * { * MakeMouv(); * }*/ RayDebug(); worldEnumSwipe = enumSwipe; // TODO : OK MY DUDE WTF IS THIS }
public void CheckDirection(swipeDirection swipeDir) { // Check dans quel direction le joueur swipe switch (swipeDir) { case swipeDirection.Front: CheckRaycast(Vector3Custom.forward); break; case swipeDirection.Right: CheckRaycast(Vector3Custom.right); break; case swipeDirection.Left: CheckRaycast(Vector3Custom.left); break; case swipeDirection.Back: CheckRaycast(Vector3Custom.back); break; } }
public void CheckDirection(swipeDirection swipeDir) { // Check dans quel direction le joueur swipe switch (swipeDir) { case swipeDirection.Front: CheckWhenToMove(_DirectionCustom.left); break; case swipeDirection.Right: CheckWhenToMove(_DirectionCustom.forward); break; case swipeDirection.Left: CheckWhenToMove(_DirectionCustom.backward); break; case swipeDirection.Back: CheckWhenToMove(_DirectionCustom.right); break; } }
private void move() { transform.position += Time.deltaTime * direction * (moveSpeed - addSpeed); //move //from here its about turns if (!canMakeATurn) { return; } Vector3 temp = transform.eulerAngles; float num; swipeDirection swipe = this.swipe(); if (Input.GetKeyDown("left") || swipe == swipeDirection.left) { temp.y -= 90; num = direction.z; direction.z = direction.x; direction.x = -num; canMakeATurn = false; faceTo = temp; Invoke("anableTurn", 0.3f); } if (Input.GetKeyDown("right") || swipe == swipeDirection.right) { temp.y += 90; num = direction.z; direction.z = -direction.x; direction.x = num; canMakeATurn = false; faceTo = temp; Invoke("anableTurn", 1f); } }
public bool IsSwiping(swipeDirection dir) { return(dir == Direction); }
void Update() { if ((Input.GetMouseButtonDown(0) && touchable_area.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))) { //Debug.Log("INSIDE TOUCH AREA"); insideTouchArea = true; } if ((Input.GetMouseButtonDown(0) && !touchable_area.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))) { //Debug.Log("NO! outside touch area"); insideTouchArea = false; } if (insideTouchArea == true) { if (Input.GetMouseButtonDown(0)) { worldPositionOfMouseStart = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z - Camera.main.transform.position.z)); } if (Input.GetMouseButtonUp(0)) { worldPositionOfMouseEnd = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z - Camera.main.transform.position.z)); deltaX = worldPositionOfMouseEnd.x - worldPositionOfMouseStart.x; deltaY = worldPositionOfMouseEnd.y - worldPositionOfMouseStart.y; if (Mathf.Abs(deltaY) > Mathf.Abs(deltaX)) { // vertical swipe. now figure out up or down swipe if (deltaY > 0) { sDir = swipeDirection.Up; /* * if going DOWN and swipped UP then change waypoint to UP (if up exists) * else if there was an input other UP, then SET then no further direction input (swipe) can be taken until it reaches it's curr wayPoint. * * set currDir to UP. */ if (pathScript.currDir == plaerFollowingPath.currDirection.Down)// && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theUpWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theUpWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Up; } } } else { sDir = swipeDirection.Down; if (pathScript.currDir == plaerFollowingPath.currDirection.Up)// && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theDownWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theDownWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Down; } } } } else { if (deltaX > 0) { sDir = swipeDirection.Right; if (pathScript.currDir == plaerFollowingPath.currDirection.Left)// && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theRightWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theRightWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Right; } } } else { sDir = swipeDirection.Left; if (pathScript.currDir == plaerFollowingPath.currDirection.Right)// && !pathScript.take90degreeTurn) { if (pathScript.currentWaypoint.theLeftWaypoint) { pathScript.currentWaypoint = pathScript.currentWaypoint.theLeftWaypoint.GetComponent <selectingPath>().thisWaypoint; pathScript.playerParentTransform.right = -1 * (pathScript.currentWaypoint.mainWpTransform.position - pathScript.playerParentTransform.position); pathScript.currDir = plaerFollowingPath.currDirection.Left; } } } } } } }
// Calcul the swipe angle of the player public void NextDirection() { //check if this gameObject is a mirror cube if (gameObject.GetComponent <_MirrorCube>() != null) { mirrorMove = true; } if (!isStatic) { // Calcul the swip angle currentSwipePos = DataManager.instance.inputPosition; distanceTouch = Vector3.Distance(baseSwipePos, currentSwipePos); angleDirection = Mathf.Abs(Mathf.Atan2(currentSwipePos.y - baseSwipePos.y, baseSwipePos.x - currentSwipePos.x) * 180 / Mathf.PI - 180); KUBNord = Camera_ZoomScroll.KUBNordScreenAngle; KUBWest = Camera_ZoomScroll.KUBWestScreenAngle; KUBSud = Camera_ZoomScroll.KUBSudScreenAngle; KUBEst = Camera_ZoomScroll.KUBEstScreenAngle; // Check in which direction the player swiped if (angleDirection < KUBNord && angleDirection > KUBEst) { enumSwipe = swipeDirection.Front; } else if (angleDirection < KUBWest && angleDirection > KUBNord) { enumSwipe = swipeDirection.Left; } else if (angleDirection < KUBSud && angleDirection > KUBWest) { enumSwipe = swipeDirection.Back; } else if (angleDirection < KUBEst && angleDirection > KUBSud) { enumSwipe = swipeDirection.Right; } else { if (angleDirection > 180) { inverseAngleDirection = angleDirection - 180; } else { inverseAngleDirection = angleDirection + 180; } if (inverseAngleDirection < KUBNord && inverseAngleDirection > KUBEst) { enumSwipe = swipeDirection.Back; } else if (inverseAngleDirection < KUBWest && inverseAngleDirection > KUBNord) { enumSwipe = swipeDirection.Right; } else if (inverseAngleDirection < KUBSud && inverseAngleDirection > KUBWest) { enumSwipe = swipeDirection.Front; } else if (inverseAngleDirection < KUBEst && inverseAngleDirection > KUBSud) { enumSwipe = swipeDirection.Left; } } if (distanceTouch > DataManager.instance.swipeMinimalDistance) { CheckDirection(enumSwipe); } } }
// Use this for initialization void Start() { if (PlayerPrefs.GetInt("firstLaunch") == 0) { Debug.Log("first launch"); PlayerPrefs.SetInt("Player 1st Score", 0); PlayerPrefs.SetInt("Player 2nd Score", 0); PlayerPrefs.SetInt("Player 3rd Score", 0); PlayerPrefs.SetInt("Player 4th Score", 0); PlayerPrefs.SetInt("Player 5th Score", 0); PlayerPrefs.SetInt("firstLaunch", 1); } else { Debug.Log("not first launch"); } endSlate.gameObject.SetActive(false); domEye = GameObject.Find("eye").GetComponent<persisEye>().dominantEye; pickAct(); lastSwipe = swipeDirection.up; audioSourse = this.gameObject.GetComponent<AudioSource>(); audioSourse.clip = music[0]; audioSourse.Play(); StartCoroutine(beatWait()); }
//is used for the weights sprites private void squats() { if (Input.touches.Length > 0) { Touch t = Input.GetTouch(0); if (t.phase == TouchPhase.Began) { firstPress = new Vector2(t.position.x, t.position.y); } if (t.phase == TouchPhase.Ended) { secondPress = new Vector2(t.position.x, t.position.y); swipe = new Vector2(secondPress.x - firstPress.x, secondPress.y - firstPress.y); swipe.Normalize(); //i framer per swipe. cant do the same swipe direction in a row if (swipe.y > 0 && (swipe.x > -0.5f || swipe.x < 0.5f) && lastSwipe == swipeDirection.down) { //handDebug.text = "swipe up"; lastSwipe = swipeDirection.up; touchSprite.setFrame(); if (acceptBeat == true) { score += 10 * (currentDiff + 1); beatHit = true; } else { lives -= 1; endPage(); } } if (swipe.y < 0 && (swipe.x > -0.5f || swipe.x < 0.5f) && lastSwipe == swipeDirection.up) { //handDebug.text = "swipe down"; lastSwipe = swipeDirection.down; touchSprite.setFrame(); if (acceptBeat == true) { score += 10 * (currentDiff + 1); beatHit = true; } else { lives -= 1; endPage(); } } } } }
void pickAct() { //hide old activaties if (randomZone == 1 || randomZone == 4) { //jump blueTouch[0].SetActive(false); blueTouch[0].GetComponent<activityObject>().Reset(); jumped = false; //squat blueTouch[1].SetActive(false); blueTouch[1].GetComponent<activityObject>().Reset(); lastSwipe = swipeDirection.up; //swim redAxis[0].SetActive(false); redAxis[0].GetComponent<activityObject>().Reset(); //run redAxis[1].SetActive(false); redAxis[1].GetComponent<activityObject>().Reset(); } else if (randomZone == 2 || randomZone == 3) { //swim blueAxis[0].SetActive(false); blueAxis[0].GetComponent<activityObject>().Reset(); //run blueAxis[1].SetActive(false); blueAxis[1].GetComponent<activityObject>().Reset(); //jump redTouch[0].SetActive(false); redTouch[0].GetComponent<activityObject>().Reset(); jumped = false; //squat redTouch[1].SetActive(false); redTouch[1].GetComponent<activityObject>().Reset(); lastSwipe = swipeDirection.up; } //select new activaties randomZone = Random.Range(1, 4); GameObject tempAct; if (randomZone == 1 || randomZone == 4) { tempAct = blueTouch[Random.Range(0, 2)]; tempAct.SetActive(true); touchSprite = tempAct.GetComponent<activityObject>().sprite.GetComponent<characterSprites>(); changeActivity(tempAct.GetComponent<activityObject>().hanActiv); //move to less dom eye if (domEye == eyes.right) { tempAct.GetComponent<Camera>().rect = new Rect(0, 0, 0.5f, 1); } else { tempAct.GetComponent<Camera>().rect = new Rect(0.5f, 0, 0.5f, 1); } tempAct = redAxis[Random.Range(0, 2)]; tempAct.SetActive(true); axisSprite = tempAct.GetComponent<activityObject>().sprite.GetComponent<characterSprites>(); changeActivity(tempAct.GetComponent<activityObject>().axisActiv); //move to more dominant eye side if (domEye == eyes.right) { tempAct.GetComponent<Camera>().rect = new Rect(0.5f, 0, 0.5f, 1); } else { tempAct.GetComponent<Camera>().rect = new Rect(0, 0, 0.5f, 1); } } else if (randomZone == 2 || randomZone == 3) { tempAct = blueAxis[Random.Range(0, 2)]; tempAct.SetActive(true); axisSprite = tempAct.GetComponent<activityObject>().sprite.GetComponent<characterSprites>(); changeActivity(tempAct.GetComponent<activityObject>().axisActiv); //move to less dominant eye side if (domEye == eyes.right) { tempAct.GetComponent<Camera>().rect = new Rect(0, 0, 0.5f, 1); } else { tempAct.GetComponent<Camera>().rect = new Rect(0.5f, 0, 0.5f, 1); } tempAct = redTouch[Random.Range(0, 2)]; tempAct.SetActive(true); touchSprite = tempAct.GetComponent<activityObject>().sprite.GetComponent<characterSprites>(); changeActivity(tempAct.GetComponent<activityObject>().hanActiv); //move to more dominant eye side if (domEye == eyes.right) { tempAct.GetComponent<Camera>().rect = new Rect(0.5f, 0, 0.5f, 1); } else { tempAct.GetComponent<Camera>().rect = new Rect(0, 0, 0.5f, 1); } } }
public bool isSwiping(swipeDirection dir) { return((Direction & dir) == dir); }
public void NextDirection() { if (!isStatic) { // Calcul the swip angle currentSwipePos = _DataManager.instance.inputPosition; distanceTouch = Vector3.Distance(baseSwipePos, currentSwipePos); angleDirection = Mathf.Abs(Mathf.Atan2(currentSwipePos.y - baseSwipePos.y, baseSwipePos.x - currentSwipePos.x) * 180 / Mathf.PI - 180); KUBNord = _InGameCamera.KUBNordScreenAngle; KUBWest = _InGameCamera.KUBWestScreenAngle; KUBSud = _InGameCamera.KUBSudScreenAngle; KUBEst = _InGameCamera.KUBEstScreenAngle; // Check in which direction the player swiped if (angleDirection < KUBNord && angleDirection > KUBEst) { enumSwipe = swipeDirection.Front; } else if (angleDirection < KUBWest && angleDirection > KUBNord) { enumSwipe = swipeDirection.Left; } else if (angleDirection < KUBSud && angleDirection > KUBWest) { enumSwipe = swipeDirection.Back; } else if (angleDirection < KUBEst && angleDirection > KUBSud) { enumSwipe = swipeDirection.Right; } else { if (angleDirection > 180) { inverseAngleDirection = angleDirection - 180; } else { inverseAngleDirection = angleDirection + 180; } if (inverseAngleDirection < KUBNord && inverseAngleDirection > KUBEst) { enumSwipe = swipeDirection.Back; } else if (inverseAngleDirection < KUBWest && inverseAngleDirection > KUBNord) { enumSwipe = swipeDirection.Right; } else if (inverseAngleDirection < KUBSud && inverseAngleDirection > KUBWest) { enumSwipe = swipeDirection.Front; } else if (inverseAngleDirection < KUBEst && inverseAngleDirection > KUBSud) { enumSwipe = swipeDirection.Left; } } if (distanceTouch > _DataManager.instance.swipeMinimalDistance) { CheckDirection(enumSwipe); } } }
// Calcul the swipe angle of the player IEnumerator SwipeDirection(Vector3 position) { Vector2 dirPos; // Calcul the swip angle dirPos = position; float distance = Vector3.Distance(baseSwipePos, dirPos); if (distance > minimumSizeSwipe) { angleDirection = Mathf.Abs(Mathf.Atan2(dirPos.y - baseSwipePos.y, baseSwipePos.x - dirPos.x) * 180 / Mathf.PI - 180); yield return(angleDirection); KUBNord = Camera_ZoomScroll.KUBNordScreenAngle; KUBWest = Camera_ZoomScroll.KUBWestScreenAngle; KUBSud = Camera_ZoomScroll.KUBSudScreenAngle; KUBEst = Camera_ZoomScroll.KUBEstScreenAngle; // Check in which direction the player swiped if (angleDirection < KUBNord && angleDirection > KUBEst) { enumSwip = swipeDirection.Front; } else if (angleDirection < KUBWest && angleDirection > KUBNord) { enumSwip = swipeDirection.Left; } else if (angleDirection < KUBSud && angleDirection > KUBWest) { enumSwip = swipeDirection.Back; } else if (angleDirection < KUBEst && angleDirection > KUBSud) { enumSwip = swipeDirection.Right; } else { if (angleDirection > 180) { inverseAngleDirection = angleDirection - 180; } else { inverseAngleDirection = angleDirection + 180; } if (inverseAngleDirection < KUBNord && inverseAngleDirection > KUBEst) { enumSwip = swipeDirection.Back; } else if (inverseAngleDirection < KUBWest && inverseAngleDirection > KUBNord) { enumSwip = swipeDirection.Right; } else if (inverseAngleDirection < KUBSud && inverseAngleDirection > KUBWest) { enumSwip = swipeDirection.Front; } else if (inverseAngleDirection < KUBEst && inverseAngleDirection > KUBSud) { enumSwip = swipeDirection.Left; } } yield return(enumSwip); DoSwip(); } else if (distance <= minimumSizeSwipe && isVentouzed == true) { Debug.Log("CANCEL VENTOUZE"); SetInteractingFalse(); } }