|
Author
|
Message
|
|
Senior Member
Join Date: Aug 2022
Location: Colombia
|

10-13-2022
, 20:49
Re: How do you make one entity rotate at a certain speed toward another?
|
#1
|
Quote:
Originally Posted by LiZou Mapper
Hello !
This is method how I use to make the NPC rotate towards the enemy, but it's boring and bad.
PHP Code:
pev(ent, pev_origin, vOrigin) pev(victim, pev_origin, vVicOrigin)
xs_vec_sub(vVicOrigin, vOrigin, vVector)
// Convert vector to angles. vector_to_angle(vVector, vAngles)
vAngles[0] = 0.0 vAngles[2] = 0.0 pev(ent, pev_angles, vAngles)
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 setAIMtoORIGIN( Client, Target ) { static Float:__fl_POrigin[3], Float:__fl_TOrigin[3];
entity_get_vector( Client, 0, __fl_POrigin ); entity_get_vector( Target, 0, __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_vector( Client, EV_VEC_angles, __fl_Aim ); entity_set_int( Client, EV_INT_fixangle, 1 ); }
Last edited by MrPickles; 10-13-2022 at 20:52.
|
|
|
|