Raised This Month: $ Target: $400
 0% 

[solved] velocity to a direction


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-12-2009 , 22:38   Re: velocity to a direction
Reply With Quote #4

Code:
// rotates "vecIn" along the X axis with a "rotation" angle stock rotateVectorX(const Float:vecIn[3], Float:rotation, anglemode:measurement, Float:vecOut[3]) {     vecOut[1] = (vecIn[1] * floatcos(rotation, measurement)) - (vecIn[2] * floatsin(rotation, measurement));     vecOut[2] = (vecIn[1] * floatsin(rotation, measurement)) - (vecIn[2] * floatcos(rotation, measurement));     vecOut[0] = vecIn[0]; } // rotates "vecIn" along the Y axis with a "rotation" angle stock rotateVectorY(const Float:vecIn[3], Float:rotation, anglemode:measurement, Float:vecOut[3]) {     vecOut[2] = (vecIn[2] * floatcos(rotation, measurement)) - (vecIn[0] * floatsin(rotation, measurement));     vecOut[0] = (vecIn[2] * floatsin(rotation, measurement)) - (vecIn[0] * floatcos(rotation, measurement));     vecOut[1] = vecIn[1]; } // rotates "vecIn" along the Z axis with a "rotation" angle stock rotateVectorZ(const Float:vecIn[3], Float:rotation, anglemode:measurement, Float:vecOut[3]) {     vecOut[0] = (vecIn[0] * floatcos(rotation, measurement)) - (vecIn[1] * floatsin(rotation, measurement));     vecOut[1] = (vecIn[0] * floatsin(rotation, measurement)) - (vecIn[1] * floatcos(rotation, measurement));     vecOut[2] = vecIn[2]; }

For your situation you can do:
Code:
new iEyes[3], Float:eyes[3]; get_user_origin(client, iEyes, 1); IVecFVec(iEyes, eyes); new iAim[3], Float:aim[3]; get_user_origin(client, iAim, 3); IVecFVec(iAim, aim); new Float:vector[3]; vector[0] = aim[0] - eyes[0]; vector[1] = aim[1] - eyes[1]; vector[2] = aim[2] - eyes[2]; // to left: rotateVectorZ(vector, -90.0, degrees, vector); // to right: rotateVectorZ(vector, 90.0, degrees, vector); // to backwards: rotateVectorZ(vector, 180.0, degrees, vector); // for forwards, don't rotate it at all new Float:length = vector_length(vector); vector[0] = vector[0] / length * /* your desired speed */; vector[1] = vector[1] / length * /* your desired speed */; vector[2] = vector[2] / length * /* your desired speed */;
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode