AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Velocity from player eyes. (https://forums.alliedmods.net/showthread.php?t=252049)

FromTheFuture 11-24-2014 11:41

Velocity from player eyes.
 
Hi, how to throw grenade from player eyes position?

klippy 11-24-2014 13:25

Re: Velocity from player eyes.
 
Perhaps velocity_by_aim()?

FromTheFuture 11-24-2014 13:55

Re: Velocity from player eyes.
 
Quote:

Originally Posted by KliPPy (Post 2227876)
Perhaps velocity_by_aim()?

I'm try to use it, but grenade flies from the hand, not from the eyes.
But I will try again.

klippy 11-24-2014 14:03

Re: Velocity from player eyes.
 
I don't think so. If it flew from the hand, it would be the attachment origin, not the aim origin. However, you may try this:
PHP Code:

new FloatfvOrigin[3], FloatfvViewOfs[3];
pev(idpev_originfvOrigin);
pev(idpev_view_ofsfvViewOfs);
xs_vec_add(fvOriginfvViewOfsfvOrigin); 

After that, your fvOrigin[] variable should hold eyes position.

FromTheFuture 11-24-2014 14:10

Re: Velocity from player eyes.
 
Quote:

Originally Posted by KliPPy (Post 2227884)
I don't think so. If it flew from the hand, it would be the attachment origin, not the aim origin. However, you may try this:
PHP Code:

new FloatfvOrigin[3], FloatfvViewOfs[3];
pev(idpev_originfvOrigin);
pev(idpev_view_ofsfvViewOfs);
xs_vec_add(fvOriginfvViewOfsfvOrigin); 

After that, your fvOrigin[] variable should hold eyes position.

Thank U. But how I can add velocity to it?
PHP Code:

public fw_SetModel(entity, const model[])
{
    new 
id pev(entitypev_owner);
    
    if(
equali(model"models/w_hegrenade.mdl"))
    {    
        new 
Floatvel[3];
        
pev(entitypev_velocityvel);
        
        if(!
vel[0]) return;
        
        
        
set_pev(entitypev_modelindexm);
        
set_pev(entitypev_movetypeMOVETYPE_FLYMISSILE)
        
        new 
FloatfvOrigin[3], FloatfvViewOfs[3];
        
pev(idpev_originfvOrigin);
        
pev(idpev_view_ofsfvViewOfs);
        
xs_vec_add(fvOriginfvViewOfsfvOrigin);  

        
set_pev(entitypev_velocity, ???) // ???
            
        
set_pev(entitypev_nextthinkget_gametime() + 99999.9);
    }
    



klippy 11-24-2014 14:46

Re: Velocity from player eyes.
 
Well, in that case:
Code:

new Float: fvAngle[3];
pev(id, pev_v_angle, fvAngle); // Get player's view angle
angle_vector(fvAngle, ANGLEVECTOR_FORWARD, fvAngle); // Transfer angle vector to a vector
xs_vec_normalize(fvAngle, fvAngle); // Create unit vector
xs_vec_mul_scalar(fvAngle, 200.0, fvAngle); // Multiply vector by 200.0

After that, fvAngle[] would be velocity you want to set for your grenade. Red number in code above is velocity you want to set.

FromTheFuture 11-24-2014 15:05

Re: Velocity from player eyes.
 
KliPPy, anyway =(
http://www.youtube.com/watch?v=1rLZi...ature=youtu.be

klippy 11-24-2014 15:21

Re: Velocity from player eyes.
 
So, you mean it is offset a bit to the left? You could've said it at the beginning...
I don't think its the problem in the code, but in your model. It could have wrong origin. Try testing it with another model that you are 100% percent sure it has centered origin.

FromTheFuture 11-24-2014 17:41

Re: Velocity from player eyes.
 
Quote:

Originally Posted by KliPPy (Post 2227910)
So, you mean it is offset a bit to the left? You could've said it at the beginning...
I don't think its the problem in the code, but in your model. It could have wrong origin. Try testing it with another model that you are 100% percent sure it has centered origin.

I said it before, just I did not know about model .qc origin.

FromTheFuture 11-24-2014 18:20

Re: Velocity from player eyes.
 
Thank You again, I found correct models.


All times are GMT -4. The time now is 17:39.

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