Raised This Month: $ Target: $400
 0% 

Using velocity_by_aim() to Get Other Directions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 08-05-2010 , 15:31   Using velocity_by_aim() to Get Other Directions
Reply With Quote #1

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?
__________________

Last edited by hleV; 08-05-2010 at 15:41.
hleV is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-05-2010 , 15:43   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #2

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]);
__________________

Last edited by Hunter-Digital; 08-05-2010 at 15:48.
Hunter-Digital is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 08-05-2010 , 16:19   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #3

Didn't help.
Or I may need an example to fit it into my code.
__________________

Last edited by hleV; 08-05-2010 at 16:35.
hleV is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 08-05-2010 , 21:30   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #4

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

__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 08-06-2010 , 10:12   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #5

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?
__________________
hleV is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 08-06-2010 , 11:25   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #6

Quote:
Originally Posted by hleV View Post
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?
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 08-06-2010 , 11:50   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #7

It gives me strange direction if I multiply X, Y, and Z by let's say 1.1.
__________________

Last edited by hleV; 08-06-2010 at 11:52.
hleV is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-06-2010 , 13:18   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #8

Quote:
Originally Posted by hleV View Post
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
__________________

Last edited by Hunter-Digital; 08-06-2010 at 13:24.
Hunter-Digital is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 08-06-2010 , 14:48   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #9

Quote:
Originally Posted by Hunter-Digital View Post
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).
__________________

Last edited by hleV; 08-06-2010 at 15:00.
hleV 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 04:00.


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