Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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
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 15:33.


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