void HandleInput() { if (Input.GetMouseButtonDown(0)) { tapPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition); //hladame throwable objekt activeThrowable = FindThrowable(); //ak sme ho nasli tak mu zavolame Attach, vypneme mu gravitaciu if (activeThrowable != null) { activeThrowable.Attach(); } } else if (Input.GetMouseButton(0)) { //ked pustime palec, tak sa zavola Dettach objektu throwable ktory mu zapne gravitaciu a spadne naspat nazem //zistujeme pohyb v priestore cez x,y poziciu mysi a z poziciu objektu relativne na kameru if (activeThrowable != null) { Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * Mathf.Abs(Camera.main.transform.position.z - activeThrowable.transform.position.z)); position.z = activeThrowable.transform.position.z; activeThrowable.followPoint = position; } } else if (Input.GetMouseButtonUp(0)) { releasePosition = Camera.main.ScreenToViewportPoint(Input.mousePosition); //ked pustime palec, tak sa zavola Dettach objektu throwable ktory mu zapne gravitaciu a spadne naspat nazem if (activeThrowable != null) { activeThrowable.Dettach(); } activeThrowable = null; } }
private void TeleportToHand(Hand pointerHand) { // Store default attachment flags Hand.AttachmentFlags attachmentFlags = Hand.defaultAttachmentFlags & ~Hand.AttachmentFlags.SnapOnAttach & ~Hand.AttachmentFlags.DetachOthers & ~Hand.AttachmentFlags.VelocityMovement; // Move object before attach otherwise the player remote controls the object transform.position = pointerHand.gameObject.transform.position + offset; // Attach object and store hand for future reference pointerHand.AttachObject(gameObject, GrabTypes.Grip, attachmentFlags); this.pointerHand = pointerHand; if (throwable) { throwable.Attach(); } // Reset material colour otherwise object stays green ResetMat(); }
private void HandleInput() { if (Input.GetMouseButtonDown(0)) { //hladame throwable objekt activeThrowable = FindThrowable(); //ak sme ho nasli tak mu zavolame Attach if (activeThrowable != null) { activeThrowable.Attach(); lastPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition); lastTime = Time.time; } } else if (Input.GetMouseButton(0)) { lastPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition); //ked pustime palec, tak sa zavola Dettach objektu throwable ktory mu zapne gravitaciu a spadne naspat nazem //zistujeme pohyb v priestore cez x,y poziciu mysi a z poziciu objektu relativne na kameru if (activeThrowable != null) { Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * Mathf.Abs(Camera.main.transform.position.z - activeThrowable.transform.position.z)); position.z = activeThrowable.transform.position.z; Vector3 dir = position - activeThrowable.transform.position; float velocityMultiplier = dir.magnitude / Time.deltaTime; Vector3 velocity = dir * velocityMultiplier; activeThrowable.GetRigidbody().velocity = velocity; lastPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition); lastTime = Time.time; } } else if (Input.GetMouseButtonUp(0)) { //ked pustime palec, tak sa zavola Dettach objektu if (activeThrowable != null) { float deltaTime = Time.time - lastTime; releasePosition = Camera.main.ScreenToViewportPoint(Input.mousePosition); Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * Mathf.Abs(Camera.main.transform.position.z - activeThrowable.transform.position.z)); position.z = activeThrowable.transform.position.z; Vector3 dir = position - activeThrowable.transform.position; if (dir.magnitude / deltaTime > minimalSwipeVelocity) { Vector3 velocity = dir.normalized * throwMultiplier; velocity.z = zVelocity; activeThrowable.Throw(velocity); } activeThrowable.Dettach(); activeThrowable = null; } } }