Raised This Month: $ Target: $400
 0% 

[solved] velocity to a direction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-12-2009 , 20:52   [solved] velocity to a direction
Reply With Quote #1

I searched for this in some dodge plugins but I don't understand anything... floatabs() and all that, can anyone explain how can I set a velocity in a direction relative to player's view ?

like... I am looking forward and I want the velocity to be to my left, right, back or just forward
__________________
Hunter-Digital is offline
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 #2

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 #3

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 #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
Dr.G
Senior Member
Join Date: Nov 2008
Old 05-13-2009 , 03:53   Re: velocity to a direction
Reply With Quote #5

PHP Code:
public throw_something(id)
{
 new 
FloatOrigin[3]
 
 
pev(idpev_origin Origin)
 
Origin[2] += 28
 
new Float:fVelocity[3]
 
 new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
 
 if(!
iEnt)
  return 
PLUGIN_HANDLED
 
 velocity_by_aim
(id1000fVelocity)
 
set_pev(iEntpev_velocityfVelocity)
 
set_pev(iEntpev_classname"iClassname")
 
 
engfunc(EngFunc_SetSizeiEntFloat:{-1.0, -7.0, -1.0}, Float:{1.07.01.0})
 
engfunc(EngFunc_SetModel,iEnt"iMdl.mdl")
 
 
set_pev(iEntpev_originOrigin)
 
set_pev(iEntpev_solidSOLID_TRIGGER)
 
set_pev(iEntpev_movetypeMOVETYPE_TOSS)
 
set_pev(iEntpev_ownerid)

is it something like that you are looking for?
__________________
Dr.G is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-13-2009 , 06:12   Re: velocity to a direction
Reply With Quote #6

http://forums.alliedmods.net/showthread.php?p=88618

PHP Code:
        case UT_RIGHT:
        {
            new 
Float:force float(get_pcvar_num(baseforce))
            new 
Float:vector[3]
            
entity_get_vector(id,EV_VEC_angles,vector)
            
engfunc(EngFunc_MakeVectors,vector)
            new 
Float:v_right[3]
            
get_global_vector(GL_v_right,v_right)
            
entity_get_vector(id,EV_VEC_velocity,vector)        
            
vector[0] = v_right[0] * force
            vector
[1] = v_right[1] * force
            vector
[2] = 220.0 
            entity_set_vector
(id,EV_VEC_velocity,vector
            
domove[id] = UT_NONE
            
return PLUGIN_CONTINUE
        
}    
        case 
UT_LEFT:
        {
            new 
Float:force float(get_pcvar_num(baseforce)) * -1.0
            
new Float:vector[3]
            
entity_get_vector(id,EV_VEC_angles,vector)
            
engfunc(EngFunc_MakeVectors,vector)
            new 
Float:v_right[3]
            
get_global_vector(GL_v_right,v_right)
            
entity_get_vector(id,EV_VEC_velocity,vector)        
            
vector[0] = v_right[0] * force
            vector
[1] = v_right[1] * force
            vector
[2] = 220.0 
            entity_set_vector
(id,EV_VEC_velocity,vector
            
domove[id] = UT_NONE
            
return PLUGIN_CONTINUE
        

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-13-2009 , 10:38   Re: velocity to a direction
Reply With Quote #7

yep, I managed to do it just perfectly using that code connor, thanks
__________________
Hunter-Digital 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