S
S
Serpent242021-01-26 21:21:22
Unity
Serpent24, 2021-01-26 21:21:22

Track the position of the pressed mouse button?

There is a mechanic, you press the mouse button - the object flies up, release the button - it clings to the surface (with the help of raycast, it is checked to what object can be fixed). So, you need to implement the following - holding down the mouse button and pulling it down (range from 0 to 1) changes its speed, for example. if from 0 to 0.25 = speed like this then etc. Please tell me how to track the clamped mouse? Thanks in advance! (I'll attach part of the code)

if (Input.GetKeyDown(KeyCode.Mouse0))
        {       
            _rigidbody.isKinematic = false;
            _rigidbody.AddForce(Vector3.up * _jumpforce, ForceMode.Impulse);
        }
        if (Input.GetKeyUp(KeyCode.Mouse0))
        {
            Ray ray = new Ray (transform.position, Vector3.forward);
            if (Physics.Raycast(ray, out RaycastHit hitInfo))
            {
                if (hitInfo.collider.TryGetComponent(out Block block))
                {
                    _rigidbody.isKinematic = false;
                }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question