Comments and answers for "Add force for long pass ball"
http://answers.unity.com/questions/1630463/add-force-for-long-pass-ball.html
The latest comments and answers for the question "Add force for long pass ball"Comment by tormentoarmagedoom on tormentoarmagedoom's comment
http://answers.unity.com/comments/1630469/view.html
Nice!
Using normalize, makes you know the "force quantity" independent of the distance. So its usefull to move things. You can also move it wothout forces to mantain a constant speed, using transform.translate or changing transform.position.
Good luck!
Bye!Fri, 10 May 2019 11:39:38 GMTtormentoarmagedoomComment by DaReign on DaReign's answer
http://answers.unity.com/comments/1630468/view.html
Hi thanks for answer
1. For short pass I tried normalize vector and maybe if you also mention about that then it is right approach. I will try figure it out ;).
2. For long pass I did stupid mistake I used transform.up insted Vector3.up the correct code shold look like this
rb.AddForce((target.position - transform.position) * thrust, ForceMode.Impulse);
rb.AddForce(Vector3.up *5, ForceMode.Impulse);
And it is working ;)Fri, 10 May 2019 11:32:43 GMTDaReignAnswer by tormentoarmagedoom
http://answers.unity.com/answers/1630464/view.html
Hallo.
First Qust:
AddForce is a vector. Doing this;
target.position - transform.position
You calculate a vector with the correct direction, but the magnitude of the vector depends on the distance between the 2 points. To have a better control of the force, you should convert that vector into a known magnitude vector with the same direction. Best way to do this is to [Normalize][1] the vector (so the magnitude will be always 1)
---
Second Qst:
Meybe the best solution if you want a parabole trajectory, is to add the vertical movement as a simple translate function (or changing directly its transform.position.y) To have a correct control of the height.
I think a good solution can be, once you know the origin and final points, you can calculate the middle point of that 2 points. Then while the object is moving increase its Y component a little each frame, until reach the midpoint (midpoint in X and Z components, as Y will change). Once reached this midpoint, decrease Y component again.
Good luck!
Bye!
[1]: https://docs.unity3d.com/ScriptReference/Vector3.Normalize.htmlFri, 10 May 2019 11:09:55 GMTtormentoarmagedoom