void AssignTarget(ClimbDirection direction) { canMove = false; targetPoint = GetDestination(direction); if (targetPoint != null) { //General Movement AssignMovePoints(this.transform, targetPoint); //IK if (direction == ClimbDirection.Down || direction == ClimbDirection.Left) { StartCoroutine(MovingHands(true, targetPoint.GetComponent <ClimbPoint>())); } else { StartCoroutine(MovingHands(false, targetPoint.GetComponent <ClimbPoint>())); } if (GetTransition(direction) == ClimbTransitionType.dismount) { autoDismount = true; } current = targetPoint.GetComponent <ClimbPoint>(); } else { canMove = true; } }
public void InitClimbing() { if (enableWhenClimbing != null) { foreach (GameObject targetObj in enableWhenClimbing) { targetObj.SetActive(true); } } if (disableWhenClimbing != null) { foreach (GameObject targetObj in disableWhenClimbing) { targetObj.SetActive(false); } } current = GetClosestClimbPoint(); if (current != null) { climbSpeed = initClimbSpeed; AssignInitialIKTarget(current.GetComponent <ClimbPoint>()); AssignMovePoints(this.transform, current.transform); SetCameraRotationPoints(true, current.transform); StartCoroutine(EnableClimbing()); moveController.enabled = false; swimController.enabled = false; SetClimbAnimation(true); enableIK = true; } }
public void Dismount() { canMove = false; dismountWait = 0.0f; autoDismount = false; SetCameraRotationPoints(false); SetClimbAnimation(false); current = null; enableIK = false; DestroyAllTempObjects(); moveController.enabled = true; swimController.enabled = true; }
ClimbPoint GetClosestClimbPoint() { Climbing.ClimbPoint retVal = null; Ray ray = EnableCamera.ScreenPointToRay(InputManager.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, reachDistance, climbLayer)) { Climbing.ClimbPoint[] points = hit.transform.GetComponentsInChildren <Climbing.ClimbPoint>(); Climbing.ClimbPoint closest = null; float closetDistance = Mathf.Infinity; foreach (Climbing.ClimbPoint point in points) { if (Vector3.Distance(transform.position, point.transform.position) < closetDistance) { closest = point; closetDistance = Vector3.Distance(transform.position, point.transform.position); transform.LookAt(point.transform.position); } retVal = closest; } } return(retVal); }
void GeneratePrefab() { //Generate Object Hierarchy GameObject climbPrefab = new GameObject("ClimbPoint"); GameObject rootPosition = new GameObject("RootPosition"); rootPosition.transform.position = new Vector3(climbPrefab.transform.position.x, climbPrefab.transform.position.y - 1.5f, climbPrefab.transform.position.z); rootPosition.transform.parent = climbPrefab.transform; GameObject hands = new GameObject("Hands"); GameObject feet = new GameObject("Feet"); hands.transform.position = new Vector3(climbPrefab.transform.position.x, climbPrefab.transform.position.y, climbPrefab.transform.position.z); feet.transform.position = new Vector3(rootPosition.transform.position.x, rootPosition.transform.position.y + 0.5f, rootPosition.transform.position.z); hands.transform.parent = rootPosition.transform; feet.transform.parent = rootPosition.transform; GameObject lh = new GameObject("LeftHand"); GameObject rh = new GameObject("RightHand"); GameObject le = new GameObject("LeftElbow"); GameObject re = new GameObject("RightElbow"); lh.transform.position = new Vector3(hands.transform.position.x - 0.25f, hands.transform.position.y, hands.transform.position.z); rh.transform.position = new Vector3(hands.transform.position.x + 0.25f, hands.transform.position.y, hands.transform.position.z); le.transform.position = new Vector3(hands.transform.position.x - 2.0f, hands.transform.position.y - 0.5f, hands.transform.position.z - 1.0f); re.transform.position = new Vector3(hands.transform.position.x + 2.0f, hands.transform.position.y - 0.5f, hands.transform.position.z - 1.0f); GameObject lf = new GameObject("LeftFoot"); GameObject rf = new GameObject("RightFoot"); GameObject lk = new GameObject("LeftKnee"); GameObject rk = new GameObject("RightKnee"); lf.transform.position = new Vector3(feet.transform.position.x - 0.25f, feet.transform.position.y, feet.transform.position.z); rf.transform.position = new Vector3(feet.transform.position.x + 0.25f, feet.transform.position.y, feet.transform.position.z); lk.transform.position = new Vector3(feet.transform.position.x - 0.25f, feet.transform.position.y, feet.transform.position.z + 2.0f); rk.transform.position = new Vector3(feet.transform.position.x + 0.25f, feet.transform.position.y, feet.transform.position.z + 2.0f); lh.transform.parent = hands.transform; rh.transform.parent = hands.transform; le.transform.parent = hands.transform; re.transform.parent = hands.transform; lf.transform.parent = feet.transform; rf.transform.parent = feet.transform; lk.transform.parent = feet.transform; rk.transform.parent = feet.transform; //Add and populate script rootPosition.AddComponent <Climbing.ClimbPoint>(); Climbing.ClimbPoint climbPoint = rootPosition.GetComponent <Climbing.ClimbPoint>(); List <Climbing.ClimbIKPositions> ik = new List <Climbing.ClimbIKPositions>(); Climbing.ClimbIKPositions ikLH = new Climbing.ClimbIKPositions(); ikLH.ikType = AvatarIKGoal.LeftHand; ikLH.target = lh.transform; ik.Add(ikLH); Climbing.ClimbIKPositions ikRH = new Climbing.ClimbIKPositions(); ikRH.ikType = AvatarIKGoal.RightHand; ikRH.target = rh.transform; ik.Add(ikRH); Climbing.ClimbIKPositions ikLF = new Climbing.ClimbIKPositions(); ikLF.ikType = AvatarIKGoal.LeftFoot; ikLF.target = lf.transform; ik.Add(ikLF); Climbing.ClimbIKPositions ikRF = new Climbing.ClimbIKPositions(); ikRF.ikType = AvatarIKGoal.RightHand; ikRF.target = rf.transform; ik.Add(ikRF); climbPoint.iks = ik.ToArray(); List <Climbing.ClimbHintIKPositions> hint = new List <Climbing.ClimbHintIKPositions>(); Climbing.ClimbHintIKPositions hintLE = new Climbing.ClimbHintIKPositions(); hintLE.hintType = AvatarIKHint.LeftElbow; hintLE.target = le.transform; hint.Add(hintLE); Climbing.ClimbHintIKPositions hintRE = new Climbing.ClimbHintIKPositions(); hintRE.hintType = AvatarIKHint.RightElbow; hintRE.target = re.transform; hint.Add(hintRE); Climbing.ClimbHintIKPositions hintLK = new Climbing.ClimbHintIKPositions(); hintLK.hintType = AvatarIKHint.LeftKnee; hintLK.target = lk.transform; hint.Add(hintLK); Climbing.ClimbHintIKPositions hintRK = new Climbing.ClimbHintIKPositions(); hintRK.hintType = AvatarIKHint.RightKnee; hintRK.target = rk.transform; hint.Add(hintRK); climbPoint.hints = hint.ToArray(); }