• 11
• 9
• 10
• 9
• 10

# How to apply randomness in an impact?

This topic is 4980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Lets say I have two points x, y to apply the force between them i take the vector of the two points and i multiply it by some force. What if I want to apply some randomness in degrees? This is what i have now:
// no y force, already added.
Vector3_t cHorizontal(  vX1-vX2,0,vY1-vY2);
int nRandomDir = (rand() % (nHorizontalRandomness*2)) - nHorizontalRandomness;
// where to apply randomDir?
cHorizontal.Normalize();
cHorizontal *= vImpactNeeded;
Impact(cHorizontal);


[Edited by - _Kami_ on September 2, 2004 4:48:09 AM]

##### Share on other sites
[img=http://www.tkoc.net/rotation.jpg]

http://www.tkoc.net/rotation.jpg

Here you can see a drawing of it.. maybe easier to understand then.

##### Share on other sites
ok, this is what I came up with.. Hope this can help some others as well:)

float vDir = 45.0 * 3.14 / 180.0;  // to radiansQuaternion_t cRot(Vector3_t(0,1,0),vDir);cHorizontal = cHorizontal * cRot;cHorizontal.Normalize();cHorizontal *= vImpactNeeded;