AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved How do you make one entity rotate at a certain speed toward another? (https://forums.alliedmods.net/showthread.php?t=339977)

LiZou Mapper 10-13-2022 19:40

How do you make one entity rotate at a certain speed toward another?
 
Hello !
This is method how I use to make the NPC rotate towards the enemy, but it's boring and bad.

PHP Code:

pev(entpev_originvOrigin)
pev(victimpev_originvVicOrigin)

xs_vec_sub(vVicOriginvOriginvVector)

// Convert vector to angles.
vector_to_angle(vVectorvAngles)

vAngles[0] = 0.0
vAngles
[2] = 0.0
    
pev
(entpev_anglesvAngles

I tried to make this entity rotate but at a certain speed towards some entity like NPCs in Half-Life.It rotates from the near direction of the enemy, for example, if the enemy is on the right side of an entity, the entity will rotate towards the right direction.

Thanks in advance :)

MrPickles 10-13-2022 20:49

Re: How do you make one entity rotate at a certain speed toward another?
 
Quote:

Originally Posted by LiZou Mapper (Post 2790911)
Hello !
This is method how I use to make the NPC rotate towards the enemy, but it's boring and bad.

PHP Code:

pev(entpev_originvOrigin)
pev(victimpev_originvVicOrigin)

xs_vec_sub(vVicOriginvOriginvVector)

// Convert vector to angles.
vector_to_angle(vVectorvAngles)

vAngles[0] = 0.0
vAngles
[2] = 0.0
    
pev
(entpev_anglesvAngles

I tried to make this entity rotate but at a certain speed towards some entity like NPCs in Half-Life.It rotates from the near direction of the enemy, for example, if the enemy is on the right side of an entity, the entity will rotate towards the right direction.

Thanks in advance :)

PHP Code:


public setAIMtoORIGINClientTarget )
{
       static 
Float:__fl_POrigin[3], Float:__fl_TOrigin[3];

       
entity_get_vectorClient0__fl_POrigin );
       
entity_get_vectorTarget0__fl_TOrigin );

       
__fl_TOrigin[0] -= __fl_POrigin[0];
       
__fl_TOrigin[1] -= __fl_POrigin[1];
       
__fl_TOrigin[2] -= __fl_POrigin[2];

       static 
Float:__fl_Lenght;
       
__fl_Lenght vector_length__fl_TOrigin )

       static 
Float:__fl_Aim[3];
       
__fl_Aim[0] = __fl_TOrigin[0] / __fl_Lenght;
       
__fl_Aim[1] = __fl_TOrigin[1] / __fl_Lenght;
       
__fl_Aim[2] = __fl_TOrigin[2] / __fl_Lenght;

       
vector_to_angle__fl_Aim__fl_Aim );

       
__fl_Aim[0] *= -1;

       switch(
__fl_Aim[1])
       {
              case 
180, -180:
              {
                     
__fl_Aim[1]=-179.999999
              

              default:
              {
                     if(
__fl_Aim[1]>180.0
                     {
                           
__fl_Aim[1] -= 360
                     
}
                     else if(
__fl_Aim[1]<-180.0
                     {
                           
__fl_Aim[1] += 360
                     
}
              }
       }

       
entity_set_vectorClientEV_VEC_angles__fl_Aim );
       
entity_set_intClientEV_INT_fixangle);



LiZou Mapper 10-13-2022 21:52

Re: How do you make one entity rotate at a certain speed toward another?
 
client?
Maybe, you don't understand what I mean, you know when an NPC is idle after stopping a player behind it, slowly rotate towards player !

Maybe, you will understand now?
PHP Code:

public fw_NPC_Think(ent)
{
    
// Invalid entity?
    
if (!pev_valid(ent))
        return

    
// ...

    
static Float:vVicOrigin[3], Float:vAngles[3], victim

    victim 
pev(entpev_enemy)

    
// Get origin of enemy.
    
pev(victimpev_originvVicOrigin)

    
// Get angles of the NPC.
    
pev(entpev_anglesvAngles)

    
vAngles[1] += 1.0

    
// Set NPC new angles.
    
set_pev(entpev_anglesvAngles)

    
// Check victim in view cone?
    
if (is_in_viewcone(entvVicOrigin))
    {
        
// Make the NPC attack the enemy...

        // Think after the attack
        
set_pev(entpev_nextthinkget_gametime() + 3.0)
        return
    }

    
// ...

    // Think again!
    
set_pev(entpev_nextthinkget_gametime() + 0.1)


I'm sorry, do not know how to explain it to you?

MrPickles 10-13-2022 22:53

Re: How do you make one entity rotate at a certain speed toward another?
 
Quote:

Originally Posted by LiZou Mapper (Post 2790915)
client?
Maybe, you don't understand what I mean, you know when an NPC is idle after stopping a player behind it, slowly rotate towards player !

Maybe, you will understand now?
PHP Code:

public fw_NPC_Think(ent)
{
    
// Invalid entity?
    
if (!pev_valid(ent))
        return

    
// ...

    
static Float:vVicOrigin[3], Float:vAngles[3], victim

    victim 
pev(entpev_enemy)

    
// Get origin of enemy.
    
pev(victimpev_originvVicOrigin)

    
// Get angles of the NPC.
    
pev(entpev_anglesvAngles)

    
vAngles[1] += 1.0

    
// Set NPC new angles.
    
set_pev(entpev_anglesvAngles)

    
// Check victim in view cone?
    
if (is_in_viewcone(__int_EntityvVicOrigin))
    {
        
// Make the NPC attack the enemy...

        // Think after the attack
        
set_pev(entpev_nextthinkget_gametime() + 3.0)
        return
    }

    
// ...

    // Think again!
    
set_pev(entpev_nextthinkget_gametime() + 0.1)


I'm sorry, do not know how to explain it to you?

PHP Code:

public fw_NPC_Think(__int_Entity)
{
    if (!
_is_valid_ent(__int_Entity))
        return

    static 
__int_Victim;
    
__int_Victim entity_get_edict__int_EntityEV_ENT_enemy );

    static 
Float:__fl_Angles[3], Float:__fl_AnglesEnd[3], Float:__fl_VictimOrg[3];

    
entity_get_vector__int_Victim0__fl_VictimOrg );

    
setAIMtoORIGIN__int_Entity__fl_VictimOrg__fl_AnglesEnd );
    
entity_get_vector__int_Entity6__flAngles );

    
__fl_Angles[0] += __fl_AnglesEnd[0] - 5.0;
    
__fl_Angles[1] += __fl_AnglesEnd[1] - 5.0;
    
__fl_Angles[2] += __fl_AnglesEnd[2] - 5.0;

    
entity_set_vector__int_Entity6__fl_Angles );
    
entity_set_int__int_EntityEV_INT_fixangle);


    if (
is_in_viewcone(ent__fl_VictimOrg))
    {
        
// Make the NPC attack the enemy...

        // Think after the attack
        
set_pev(entpev_nextthinkget_gametime() + 3.0)
        return
    }

    
// ...

    // Think again!
    
set_pev(entpev_nextthinkget_gametime() + 0.1)

public 
setAIMtoORIGINClientFloat:__fl_TOrigin[3], Float:__fl_Aim[3] )
{
       static 
Float:__fl_POrigin[3];

       
entity_get_vectorClient0__fl_POrigin );

       
__fl_TOrigin[0] -= __fl_POrigin[0];
       
__fl_TOrigin[1] -= __fl_POrigin[1];
       
__fl_TOrigin[2] -= __fl_POrigin[2];

       static 
Float:__fl_Lenght;
       
__fl_Lenght vector_length__fl_TOrigin )

       static 
Float:__fl_Aim[3];
       
__fl_Aim[0] = __fl_TOrigin[0] / __fl_Lenght;
       
__fl_Aim[1] = __fl_TOrigin[1] / __fl_Lenght;
       
__fl_Aim[2] = __fl_TOrigin[2] / __fl_Lenght;

       
vector_to_angle__fl_Aim__fl_Aim );

       
__fl_Aim[0] *= -1;

       switch(
__fl_Aim[1])
       {
              case 
180, -180:
              {
                     
__fl_Aim[1]=-179.999999
              

              default:
              {
                     if(
__fl_Aim[1]>180.0
                     {
                           
__fl_Aim[1] -= 360
                     
}
                     else if(
__fl_Aim[1]<-180.0
                     {
                           
__fl_Aim[1] += 360
                     
}
              }
       }


try with this, it doesnt care if in the stock client is entity or id, when u put it in the think, change it to your index, see if works

MrPickles 10-13-2022 22:56

Re: How do you make one entity rotate at a certain speed toward another?
 
*Delete This*

LiZou Mapper 10-14-2022 10:56

Re: How do you make one entity rotate at a certain speed toward another?
 
Solved!
Thank you MrPickles !!


All times are GMT -4. The time now is 15:33.

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