AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using velocity_by_aim() to Get Other Directions (https://forums.alliedmods.net/showthread.php?t=134510)

hleV 08-05-2010 15:31

Using velocity_by_aim() to Get Other Directions
 
Hello. I want to increate player's speed using velocity.
I have two directions so far: forwards, backwards.
I need six of them: upwards, downwards, left, right.
PHP Code:

#define GOING_SPEED 320
 
enum
{
    
GO_UP,
    
GO_DOWN,
    
GO_LEFT,
    
GO_RIGHT,
    
GO_FORWARD,
    
GO_BACK
};
 
public 
client_PostThink(Client)
{
    if (!
is_user_alive(Client))
        return;
 
    static 
Float:s_Velocity[3];
    
entity_get_vector(ClientEV_VEC_velocitys_Velocity);
    
velocity_by_aim(ClientGOING_SPEEDs_Velocity);
 
    switch (
GetDirection(Client)) // Returns one of the enumerated directions
    
{
        case 
GO_FORWARD:
        {
            
// velocity_by_aim() already gave the needed velocity, do nothing
        
}
        case 
GO_BACK:
        {
            
s_Velocity[0] = -s_Velocity[0];
            
s_Velocity[1] = -s_Velocity[1];
            
s_Velocity[2] = -s_Velocity[2];
        }
    }
 
    
entity_set_vector(ClientEV_VEC_velocitys_Velocity);


So, how do I calculate the other directions? And is there a better way to do this?

Hunter-Digital 08-05-2010 15:43

Re: Using velocity_by_aim() to Get Other Directions
 
This ?

Quote:

Originally Posted by vector.inc
/* Used for angle_vector() */
#define ANGLEVECTOR_FORWARD 1
#define ANGLEVECTOR_RIGHT 2
#define ANGLEVECTOR_UP 3

/* Changes an angle vector into a vector. */
native angle_vector(const Float:vector[3], FRU, Float:ret[3]);


hleV 08-05-2010 16:19

Re: Using velocity_by_aim() to Get Other Directions
 
Didn't help. :|
Or I may need an example to fit it into my code.

meTaLiCroSS 08-05-2010 21:30

Re: Using velocity_by_aim() to Get Other Directions
 
Code:
static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params) {     int iEnt = params[1];     int iVelocity = params[2];     cell *vRet = get_amxaddr(amx, params[3]);     Vector vVector = Vector(0, 0, 0);     edict_t *pEnt = NULL;     if (iEnt < 0 || iEnt > gpGlobals->maxEntities)     {         LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", iEnt);         return 0;     }     else     {         if (iEnt > 0 && iEnt <= gpGlobals->maxClients)         {             if (!GET_PLAYER_POINTER_I(iEnt)->ingame)             {                 LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not ingame)", iEnt);                 return 0;             }             pEnt = GET_PLAYER_POINTER_I(iEnt)->pEdict;         } else {             pEnt = INDEXENT(iEnt);         }     }     if (!pEnt)     {         LogError(amx, AMX_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; }

I tried to do a modified version which supports these directions:

PHP Code:

#include <engine>
#include <fakemeta>
#include <xs>

enum Direction
{
    
DIRECTION_UP 0,
    
DIRECTION_RIGHT,
    
DIRECTION_FORWARD,
    
DIRECTION_DOWN,
    
DIRECTION_LEFT,
    
DIRECTION_BACKWARD
}

stock velocity_by_direction(iEntDirection:iWhere DIRECTION_FORWARD /* the default one */Float:flVelocityFloat:flRetVector[3])
{
    new 
Float:flBuffer[3]
    
entity_get_vector(iEntEV_VEC_v_angleflBuffer)
    
engfunc(EngFunc_MakeVectorsflBuffer)
    
    switch(
iWhere)
    {
        case 
DIRECTION_UPDIRECTION_DOWNget_global_vector(GL_v_upflBuffer)
        case 
DIRECTION_RIGHTDIRECTION_LEFTget_global_vector(GL_v_rightflBuffer)
        case 
DIRECTION_FORWARDDIRECTION_BACKWARDget_global_vector(GL_v_forwardflBuffer)
    }
    
    
xs_vec_mul_scalar(flBuffer_:iWhere <= flVelocity : -flVelocityflBuffer)
    
xs_vec_copy(flBufferflRetVector)

    return 
1



hleV 08-06-2010 10:12

Re: Using velocity_by_aim() to Get Other Directions
 
Thanks, with some small editing I managed to get it working.

However I now have a new question.
Can I retrieve the direction player is moving and increase the velocity to that direction?

joropito 08-06-2010 11:25

Re: Using velocity_by_aim() to Get Other Directions
 
Quote:

Originally Posted by hleV (Post 1263258)
Thanks, with some small editing I managed to get it working.

However I now have a new question.
Can I retrieve the direction player is moving and increase the velocity to that direction?

Get pev_velocity and multiply that vector.

Is that what you want?

hleV 08-06-2010 11:50

Re: Using velocity_by_aim() to Get Other Directions
 
It gives me strange direction if I multiply X, Y, and Z by let's say 1.1.

Hunter-Digital 08-06-2010 13:18

Re: Using velocity_by_aim() to Get Other Directions
 
Quote:

Originally Posted by hleV (Post 1262545)
Didn't help. :|
Or I may need an example to fit it into my code.

Code:

new Float:fAngles[3]
new Float:fVelocity[3]

entity_get_vector(id, EV_VEC_angles, fAngles)

angle_vector(fAngles, ANGLEVECTOR_RIGHT, fVelocity)

// fVelocity now points RIGHT

fVelocity[0] *= -1.0
fVelocity[1] *= -1.0
fVelocity[2] *= -1.0

// fVelocity now points LEFT

not tested.

If it's up and down of player you don't need to calculate these... you only need to set fVelocity[2] to a negative or positive value.
Unless you want to be up/down of player's VIEW, then you need to supply EV_VEC_v_angle

hleV 08-06-2010 14:48

Re: Using velocity_by_aim() to Get Other Directions
 
Quote:

Originally Posted by Hunter-Digital (Post 1263431)
Code:

new Float:fAngles[3]
new Float:fVelocity[3]
 
entity_get_vector(id, EV_VEC_angles, fAngles)
 
angle_vector(fAngles, ANGLEVECTOR_RIGHT, fVelocity)
 
// fVelocity now points RIGHT
 
fVelocity[0] *= -1.0
fVelocity[1] *= -1.0
fVelocity[2] *= -1.0
 
// fVelocity now points LEFT

not tested.

If it's up and down of player you don't need to calculate these... you only need to set fVelocity[2] to a negative or positive value.
Unless you want to be up/down of player's VIEW, then you need to supply EV_VEC_v_angle

I've already tested that way and it didn't work.

And in my case if I go up, that doesn't mean that I only go UP, but it also depends on where I look. If I look at the ground, I won't go forward by pressing up though, I'll still go up, but a bit forward too.

BTW this is for mod ESF, in which you can "swoop" into six directions. However setting the velocity of swoop direction gives some lame feeling once you turn from forward to let's say left (chainswooping), because default turning in that mod is more smooth and takes time to actually turn. That's why I simply need to increase the speed to the direction player is currently swooping.

BTW I've tested all possible pev/pdata settings and nothing allows to increase the swooping speed (although normal speed increases well).


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

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