Raised This Month: $51 Target: $400
 12% 

Solved How do you make one entity rotate at a certain speed toward another?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LiZou Mapper
Member
Join Date: Oct 2018
Location: The Red City !
Old 10-13-2022 , 19:40   How do you make one entity rotate at a certain speed toward another?
Reply With Quote #1

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
__________________

-------------
My Maps !
Zombie Escape Mod !
-------------


Last edited by LiZou Mapper; 10-14-2022 at 10:56. Reason: Solved!
LiZou Mapper is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 10-13-2022 , 20:49   Re: How do you make one entity rotate at a certain speed toward another?
Reply With Quote #2

Quote:
Originally Posted by LiZou Mapper View Post
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);


Last edited by MrPickles; 10-13-2022 at 20:52.
MrPickles is offline
LiZou Mapper
Member
Join Date: Oct 2018
Location: The Red City !
Old 10-13-2022 , 21:52   Re: How do you make one entity rotate at a certain speed toward another?
Reply With Quote #3

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

-------------
My Maps !
Zombie Escape Mod !
-------------


Last edited by LiZou Mapper; 10-13-2022 at 21:56. Reason: Edit on code!!
LiZou Mapper is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 10-13-2022 , 22:53   Re: How do you make one entity rotate at a certain speed toward another?
Reply With Quote #4

Quote:
Originally Posted by LiZou Mapper View Post
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

Last edited by MrPickles; 10-13-2022 at 22:57.
MrPickles is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 10-13-2022 , 22:56   Re: How do you make one entity rotate at a certain speed toward another?
Reply With Quote #5

*Delete This*

Last edited by MrPickles; 10-13-2022 at 22:56.
MrPickles is offline
LiZou Mapper
Member
Join Date: Oct 2018
Location: The Red City !
Old 10-14-2022 , 10:56   Re: How do you make one entity rotate at a certain speed toward another?
Reply With Quote #6

Solved!
Thank you MrPickles !!
__________________

-------------
My Maps !
Zombie Escape Mod !
-------------

LiZou Mapper 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 03:10.


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