User Tools

Site Tools


en:tutorials:force_points

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:tutorials:force_points [2018/05/22 11:56 (18 months ago)]
sausage
en:tutorials:force_points [2018/05/22 15:31 (18 months ago)] (current)
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 '​orxObject_ApplyForce'​ function is the pass an '​orxNULL'​ value for the last parameter which means to apply force to the centre of the object. Most of the time that is what you probably want.+The most easy way to use the ''​orxObject_ApplyForce'' function is the pass an ''​orxNULL'' value for the last parameter which means to apply force to the centre of the object. Most of the time that is what you probably want.
  
 I came across a scenario where I wanted to apply force always 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 at the left hand edge, and always in the direction that the object was facing. ​
Line 7: Line 7:
 Here is the signature for the function: Here is the signature for the function:
  
-'​orxObject_ApplyForce (orxOBJECT *_pstObject,​ const orxVECTOR *_pvForce, const orxVECTOR *_pvPoint)'​+''​orxObject_ApplyForce (orxOBJECT *_pstObject,​ const orxVECTOR *_pvForce, const orxVECTOR *_pvPoint)''
  
 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. 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.
Line 16: Line 16:
 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 '​orxObject_ApplyForce'​ function.+That way I could provide this relative point to the ''​orxObject_ApplyForce'' function.
  
 Here's what I came up with: Here's what I came up with:
Line 61: Line 61:
 </​code>​ </​code>​
  
-I'll leave it to you, the reader to pick through the Thrust() function. But in short, you provide a vector, which is relative to the centre of the object. In this case, `{ -25, 0, 0 }which means 25 pixels to the left of the object, and 0 vertically in the middle (my test object was 50 x 50 pixels). ​+I'll leave it to you, the reader to pick through the ''​Thrust()'' ​function. But in short, you provide a vector, which is relative to the centre of the object. In this case, ''​{ -25, 0, 0 }'' ​which means 25 pixels to the left of the object, and 0 vertically in the middle (my test object was 50 x 50 pixels). ​
  
 The second parameter is the strength of the force to apply. The second parameter is the strength of the force to apply.
  
-The routine checks the rotation of the object in order to work out +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: 
 + 
 +{{ :​en:​tutorials:​point-force.gif |}}
en/tutorials/force_points.txt · Last modified: 2018/05/22 15:31 (18 months ago) (external edit)