private void OnTriggerEnter(Collider other) { if (other.CompareTag("MoveObject") && other.transform.parent != null) { moveObject = other.transform.parent.GetComponent <PushPullObject>(); } }
private void OnPushPullEnd(PushPullObject pushPullObject) { if (acceptedPushPullObjectID != pushPullObject.PushPullObjectID) { return; } FadeOut(0); FadeOut(1); tutorialState = TutorialState.Step1; }
public void CancelPushingPulling() { // Update state currentState = PlayerState.None; // Process push/pull end event pushpullObject.GetComponent <PushPullObject>().OnPushPullEnd(); // Events if (OnPushPullEnd != null) { OnPushPullEnd(pushpullObject); } // Return parent of pushing/pulling body pushpullObject.transform.SetParent(pushpullObject.OriginalParent); //pushPullRigidBody = null; pushpullObject = null; // Animation animator.SetBool(isPushingHash, false); animator.SetBool(isPullingHash, false); animator.SetBool(isPushPullingHash, false); }
private IEnumerator Grab() { // Disable player movement playerMotor.canControl = false; // get push direction playerPushDir = GetPushDirection(); // populate collider bounding points dictionary dicColliderPoints = GetColliderVertexPositions(target); Vector3 startPos = player.position; Vector3 endPos = Vector3.zero; Vector3 temp = Vector3.zero; float zExtents = (dicColliderPoints[ColliderBoundsVertex.LowerForwardLeft] - dicColliderPoints[ColliderBoundsVertex.LowerBackLeft]).magnitude / 2; float xExtents = (dicColliderPoints[ColliderBoundsVertex.LowerBackRight] - dicColliderPoints[ColliderBoundsVertex.LowerBackLeft]).magnitude / 2; if (playerPushDir == PushDirection.TargetForward) { temp = target.position - (target.forward * (zExtents + (playerCtrl.radius / 2) + GrabDistance)); } else if (playerPushDir == PushDirection.TargetBack) { temp = target.position + (target.forward * (zExtents + (playerCtrl.radius / 2) + GrabDistance)); } else if (playerPushDir == PushDirection.TargetRight) { temp = target.position - (target.right * (xExtents + (playerCtrl.radius / 2) + GrabDistance)); } else if (playerPushDir == PushDirection.TargetLeft) { temp = target.position + (target.right * (xExtents + (playerCtrl.radius / 2) + GrabDistance)); } endPos = new Vector3(temp.x, player.position.y, temp.z); // move player float startTime = Time.time; playerPushState = PushState.MovingPlayer; while (Time.time < startTime + GrabMoveTime) { Vector3 lastPos = player.position; Vector3 newPos = Vector3.Lerp(startPos, endPos, (Time.time - startTime) / GrabMoveTime) - lastPos; playerCtrl.Move(newPos); yield return(null); } // set state playerPushState = PushState.None; localGrabPosition = target.position - player.position; targetLastPosition = target.position; targetLastRotation = target.eulerAngles; // smooth movement target.GetComponent <Rigidbody>().isKinematic = true; // set override push/pull parameters PushPullObject ppObj = target.GetComponent <PushPullObject>(); if (ppObj != null) { overrideParameters = ppObj.parameters; } // Slow player movement SlowSpeed(); }
// audio for push/pull box void OnSliding(PushPullObject pushPullObject) { //playerAudio.randomizePitch(boxAudioSrc); audioSource.pitch = Random.Range(.8f, 1); audioSource.PlayOneShot(boxSlide); }
void CheckPushPull() { // if player currently already pushing/pull an object then cancel the push/pull interaction if (currentState == PlayerState.PushingPulling) { CancelPushingPulling(); } // else check for any objects within distance to push/pull else { // Determine direction to cast ray Vector3 dir; if (facingDirection == FacingDirection.Right) { dir = Vector3.right; } else { dir = Vector3.left; } // cast ray RaycastHit hit; Physics.Raycast(transform.position, dir, out hit, pushpullDistance, Layers.PushPullable); if (Application.isEditor) { Debug.DrawRay(transform.position, dir * pushpullDistance, Color.red, 5f); } // Evaluate hit if (hit.collider) { //Debug.Log("Holding objecT: " + hit.collider.name); // Update player state currentState = PlayerState.PushingPulling; // Reset x velocity velocity.x = 0; // Cache pushing/pulling body pushpullObject = hit.transform.GetComponent <PushPullObject>(); //pushPullRigidBody = hit.transform.GetComponent<Rigidbody>(); pushpullObject.transform.SetParent(transform); // Set the pushing/pulling break distance pushpullBreakDistance = Vector3.Distance(pushpullObject.transform.position, transform.position); // Process interaction event to the push/pull object pushpullObject.OnPushPullStart(); // Animation animator.SetBool(isPushPullingHash, true); // Events if (OnPushPullStart != null) { OnPushPullStart(pushpullObject); } } } }