Impact/collision between objects.

Started by
0 comments, last by MrEvil 19 years, 7 months ago
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);

www.ageofconan.com
Advertisement
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]

This topic is closed to new replies.

Advertisement