This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:tutorials:force_points [2018/05/18 05:09 (6 years ago)] – created sausage | en:tutorials:physics:force_points [2020/08/31 05:37 (4 years ago)] (current) – ↷ Page moved from en:tutorials:force_points to en:tutorials:physics:force_points sausage | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Applying a force at a position point ====== | ====== Applying a force at a position point ====== | ||
- | The most easy way to use the ' | + | The most easy way to use the '' |
- | I came across a scenario where I wanted to apply force at the left hand edge, and always in the direction that the object was facing. | + | I came across a scenario where I wanted to apply force always |
- | ' | + | Here is the signature for the function: |
+ | |||
+ | '' | ||
+ | |||
+ | The first two parameters are the object and force vector to apply. But the last parameter is the position to apply the force. This position is not a local coordinate, but rather, a world position vector. Nor is the vector relative to the object rotation. | ||
+ | |||
+ | Turned out to be mathematically trickier than I expected. | ||
- | The first parameters are the object and force vector to apply. But the last parameter is the position to apply the force. This position is not a local coordinate, but rather, a world position vector. | ||
What I really wanted, was the ability to provide a point vector relative to the centre of the object, who's position and direction would remain constantly relative to the objects position and rotation. | What I really wanted, was the ability to provide a point vector relative to the centre of the object, who's position and direction would remain constantly relative to the objects position and rotation. | ||
- | That way I could provide this relative point to the ' | + | That way I could provide this relative point to the '' |
Here's what I came up with: | Here's what I came up with: | ||
Line 55: | Line 60: | ||
</ | </ | ||
+ | |||
+ | I'll leave it to you, the reader to pick through the '' | ||
+ | |||
+ | The second parameter is the strength of the force to apply. | ||
+ | |||
+ | The routine checks the rotation of the object in order to work out which direction to apply the force. Then it uses the rotation, location, and the passed in vector to work out the relative offset position of the object and direction. | ||
+ | |||
+ | Finally, a small debug is placed on top of this position to ensure all is working as expected. | ||
+ | |||
+ | When all is done, applying force to the relative point, will give the following result: | ||
+ | |||
+ | {{ tutorials: |