Sign in to follow this  
_Kami_

Impact/collision between objects.

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 this post


Link to post
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this