Apply force by clicking and dragging Unity

Asked

Viewed 225 times

0

Good morning, I’m a beginner in Unity so sorry if I talk nonsense haha

I am developing a game where I need to put a ball in a basket, what I am not able to do is to click and drag the ball to apply the force and nor change the intensity gives strength according to the distance between the point where you click and what you release your mouse. Does anyone know how?

  • Hello, welcome to SOPT. What have you tried? Edit the question and post the code you already have, so we can help you with it. Meanwhile, do the [tour] and read [Ask].

  • Yes, someone knows how. But there are a thousand ways to do it. What you’ve tried?

1 answer

1


You have to create procedures that treat an incoming event, such as the act of "clicking and dragging the mouse" (you have to study the Unity API). Procedures boil down to telling what will happen when you click and drag the mouse.

You can increment a field as many units required "per frame" (better "per second" - learn how to implement from Time.deltaTime).

You can decide that a mouse slide on the negative x-axis should increment the field and on the positive x-axis the inverse. The value of the field at the moment you release the mouse button is what will determine the amount of force to which you should give direction and direction by means of a class object Vector3 (for this you have to use the physics libraries of Unity).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.