void ForceControlls() { float dist = 100.0f; Ray raycast = new Ray(holder.transform.position, holder.transform.forward * dist); RaycastHit hit; bool bHit = Physics.Raycast(raycast, out hit); if (bHit) { int id = hit.collider.GetInstanceID(); if (hit.collider.gameObject.tag.Contains("grabblable") && currentId != id) { if (currentId != 0) { ResetCurrObj(); } MoveAlongPath moveAlong = hit.collider.gameObject.GetComponent <MoveAlongPath>(); if (moveAlong) { if (moveAlong.GetIsMoving()) { return; } } currentId = id; currentObj = hit.collider.gameObject; originalPosition = currentObj.transform.position; halfWayPosition = currentObj.transform.position; originalRotation = currentObj.transform.rotation; SetObjUseGravity(false, true); float flyDist = currObjUseGravity ? flyDistVal : 0f; SetHighlight(true, currentObj); currentObj.transform.position = new Vector3(originalPosition.x, originalPosition.y + flyDist, originalPosition.z); } else if (!hit.collider.gameObject.tag.Contains("grabblable") && currentId != 0) { SetCounter(); } else if (currentId == id) { startCleanCount = false; } } else if (currentId != 0) { SetCounter(); } if (startCleanCount) { CounterToClean(); } }
private void PullAction() { MoveAlongPath objMovePath = null; if (currentObj != null) { objMovePath = currentObj.GetComponent <MoveAlongPath>(); if (objMovePath != null && objMovePath.GetIsMoving()) { halfWayPosition = currentObj.transform.position; } //teste angle //Vector3[] path = projectileCalc.CalculatePath(transform.position, currentObj.transform.position); //projectileCalc.Show(); //projectileCalc.SetLineColor(Color.yellow); //projectileCalc.DrawLine(); } if (Vector3.Distance(transform.position, currentObj.transform.position) <= 0.2f) { hasObject = true; backOriginalPos = false; currentObj.transform.position = transform.position; if (objMovePath != null && objMovePath.GetIsMoving()) { objMovePath.Stop(); } } if (gettingObject) { time += Time.deltaTime; float speed = curve.Evaluate(time); //Vector3[] path = projectileCalc.CalculatePath(transform.position, currentObj.transform.position); //projectileCalc.Show(); //projectileCalc.SetLineColor(Color.yellow); //projectileCalc.DrawLine(); if (objMovePath != null && objMovePath.GetIsMoving()) { objMovePath.SetSight(true); //System.Array.Reverse(path); Vector3[] Simplepath = { transform.position, currentObj.transform.position }; // objMovePath.SetMoveParams(path, curve.Evaluate(0.0f), MoveAlongPath.MoveType.Speed); objMovePath.SetMoveParams(Simplepath, speed, MoveAlongPath.MoveType.Speed, null, null); } } if (Input.GetAxis("SecondaryTrigger") > 0.4f)//SteamVR_Input.GetState("forcePull", "pull", SteamVR_Input_Sources.LeftHand) { if (!gettingObject && !hasObject) { gettingObject = true; time = 0.0f; //StartCoroutine(MoveObject()); if (currentObj != null && Vector3.Distance(transform.position, currentObj.transform.position) > 0.2f) { //Vector3[] path = projectileCalc.CalculatePath(transform.position, currentObj.transform.position); //projectileCalc.Show(); //projectileCalc.SetLineColor(Color.yellow); //projectileCalc.DrawLine(); // objMovePath = currentObj.GetComponent<MoveAlongPath>(); if (objMovePath != null && !objMovePath.GetIsMoving()) { objMovePath.SetSight(true); //System.Array.Reverse(path); Vector3[] Simplepath = { transform.position, currentObj.transform.position }; // objMovePath.SetMoveParams(path, curve.Evaluate(0.0f), MoveAlongPath.MoveType.Speed); objMovePath.SetMoveParams(Simplepath, curve.Evaluate(0.0f), MoveAlongPath.MoveType.Speed, null, null); } } } } else if ((Input.GetAxis("SecondaryTrigger") < 0.4f && gettingObject))//SteamVR_Input.GetStateUp("forcePull", "pull", SteamVR_Input_Sources.LeftHand) || { projectileCalc.HideLine(); gettingObject = false; time = 0.0f; if (currentObj != null) { if (objMovePath != null) { objMovePath.Stop(); } } } }