Raised This Month: $ Target: $400
 0% 

[solved] velocity to a direction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-12-2009 , 21:04   Re: velocity to a direction
Reply With Quote #1

http://forums.alliedmods.net/showthr...750#post389750
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-12-2009 , 21:22   Re: velocity to a direction
Reply With Quote #2

Using your code I was able to make forward and backward, but left & right doesn't work right, and also with forward & backward, when I look up or down doesn't give the full throttle, is there another way ?

I could get the straight line direction
PHP Code:
new origin[3], aim[3]
get_user_origin(idorigin1)
get_user_origin(idaim3)
aim[2] = origin[2// reset x axis 
but from here I'm kinda stuck ...

edit: I tried to look into velocity_by_aim's function but I don't understand anything
PHP Code:
static cell AMX_NATIVE_CALL VelocityByAim(AMX *amxcell *params)
{
    
int iEnt params[1];
    
int iVelocity params[2];
    
cell *vRet get_amxaddr(amxparams[3]);
    
Vector vVector Vector(000);
    
edict_t *pEnt NULL;
 
    if (
iEnt || iEnt gpGlobals->maxEntities)
    {
        
LogError(amxAMX_ERR_NATIVE"Entity out of range (%d)"iEnt);
        return 
0;
    }
    else
    {
        if (
iEnt && iEnt <= gpGlobals->maxClients)
        {
            if (!
GET_PLAYER_POINTER_I(iEnt)->ingame)
            {
                
LogError(amxAMX_ERR_NATIVE"Invalid player %d (not ingame)"iEnt);
                return 
0;
            }
            
pEnt GET_PLAYER_POINTER_I(iEnt)->pEdict;
        } else {
            
pEnt INDEXENT(iEnt);
        }
    }
 
    if (!
pEnt)
    {
        
LogError(amxAMX_ERR_NATIVE"Invalid entity %d (nullent)"iEnt);
        return 
0;
    }
 
    
MAKE_VECTORS(pEnt->v.v_angle);
    
vVector gpGlobals->v_forward iVelocity;
 
    
vRet[0] = FloatToCell(vVector.x);
    
vRet[1] = FloatToCell(vVector.y);
    
vRet[2] = FloatToCell(vVector.z);
 
    return 
1;

__________________

Last edited by Hunter-Digital; 05-12-2009 at 21:35.
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-12-2009 , 22:38   Re: velocity to a direction
Reply With Quote #3

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
Reply



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