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 , 20:49   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
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
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:34.


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