AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Circular Rotation (https://forums.alliedmods.net/showthread.php?t=100048)

madeitout 08-11-2009 23:09

Circular Rotation
 
I have 2 ents and I want 1 to rotate 360 degrees around the other, kind of like the moon orbits around the earth but I need sure how to get the origins.
thank you

Exolent[jNr] 08-11-2009 23:45

Re: Circular Rotation
 
Code:
new g_iRotationAngle; new Float:g_fRadius = 100.0; new Float:g_vCenter[ 3 ]; new bool:g_bClockwise; StartRotation( iCenterEntity, iRotatingEntity, Float:fRadius, bool:bClockwise, Float:fSpeed ) {     entity_get_vector( iCenterEntity, EV_VEC_origin, g_vCenter );         g_fRadius = fRadius;         g_bClockwise = bClockwise;         new Float:fCircumference = 2.0 * M_PI * fRadius;         // speed = distance / time     // time = distance / speed         set_task( ( fCircumference / fSpeed ), "TaskDoRotate", iRotatingEntity, _, _, "b" ); } public TaskDoRotate( iEntity ) {     if( g_bClockwise )     {         if( g_iRotationAngle-- <= 0 )         {             g_iRotationAngle = 359;         }     }     else     {         g_iRotationAngle = ++g_iRotationAngle % 360;     }         new Float:vVector[ 3 ];         new iAngle = g_iRotationAngle % 90;         new Float:fSin = 1.0;     new Float:fCos = 1.0;         if( iAngle == 0 )     {         switch( g_iRotationAngle )         {             case 180: fCos = -1.0;             case 270: fSin = -1.0;         }     }     else if( g_iRotationAngle < 90 )     {         // all are positive     }     else if( g_iRotationAngle < 180 )     {         // sin is positive, others negative                 iAngle = 90 - iAngle;         fCos = -1.0;     }     else if( g_iRotationAngle < 270 )     {         // tan is positive, others negative                 fSin = -1.0;         fCos = -1.0;     }     else //if( g_iRotationAngle < 360 )     {         // cos is positive, others negative                 iAngle = 90 - iAngle;         fSin = -1.0;     }         vVector[ 0 ] = floatcos( float( iAngle ), degrees ) * g_fRadius * fCos;     vVector[ 1 ] = floatsin( float( iAngle ), degrees ) * g_fRadius * fSin;         vVector[ 0 ] += g_vCenter[ 0 ];     vVector[ 1 ] += g_vCenter[ 1 ];     vVector[ 2 ] += g_vCenter[ 2 ];         entity_set_origin( iEntity, vVector ); }

madeitout 08-12-2009 00:24

Re: Circular Rotation
 
much appriciated, +karma

madeitout 08-12-2009 01:10

Re: Circular Rotation
 
it seems that the adjacent angles go opposite ways so if i set it to clock ways, angles < 270 and < 90 rotate clockways and < 360 and < 180 rotate counterclock ways. Viceversa if i set it to counterclockways. any ideas?

Exolent[jNr] 08-12-2009 02:43

Re: Circular Rotation
 
Sorry about that. Should be fixed.


All times are GMT -4. The time now is 18:19.

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