# Impact/collision between objects.

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

## Recommended Posts

http://www.tkoc.net/rotation.jpg Player: This is the person applying the force When he collides with the 3 other objects, normally they would go in a stright line away from him. But i want to be able to specify an angle, that also should be taken into consideration. (the red lines) Ie, they crash, but I want it to go 45 degrees to the right (Rightmost example). This is what I have so far:
// c++ source.
Vector3_t cHorizontal(x2-x1, 0 y2-y1);
vRandomDir *= 45.0f * 3.1415926535f/180.0f;
cHorizontal.x = cHorizontal.x*cos(vRandomDir) + cHorizontal.x*sin(vRandomDir);
cHorizontal.z = cHorizontal.z*cos(vRandomDir) - cHorizontal.z*sin(vRandomDir);
cHorizontal.Normalize();
cHorizontal *= vImpactNeeded;
Impact(cHorizontal);



##### Share on other sites
It looks like you are trying to rotate the vector around the y-axis by vRandomdir radians, yes? you had the co-efficients right but the x and z mixed up at points.
Try:

// c++ source.
Vector3_t cHorizontal(x2-x1, 0 y2-y1);
vRandomDir *= 45.0f * 3.1415926535f/180.0f;
cHorizontal.x = cHorizontal.x*cos(vRandomDir) + cHorizontal.z*sin(vRandomDir);
cHorizontal.z = cHorizontal.z*cos(vRandomDir) - cHorizontal.x*sin(vRandomDir);
cHorizontal.Normalize();
cHorizontal *= vImpactNeeded;
Impact(cHorizontal);

<ignore this>
you also may want to make vRandomDir occasionally negative, otherwise it will always rotate more anticlockwise.. i.e
vRandomDir *= 45.0f*(rand()/RAND_MAX-0.5f) * 3.1415926535f/180.0f;
I included the rand() call because I assumed that was what vRandomDir was meant to be doing.
</ignore this>

Hope this works, but if it doesn't try using a different rotation formula.

[Edited by - MrEvil on September 6, 2004 11:44:38 AM]

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002034
×