# Impact/collision between objects.

This topic is 5157 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
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009243
• ### Who's Online (See full list)

There are no registered users currently online

×