Jump to content
  • Advertisement
Sign in to follow this  
_Kami_

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.

If you intended to correct an error in the post then please contact us.

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
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!