| 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(ent, pev_enemy)
// Get origin of enemy. pev(victim, pev_origin, vVicOrigin)
// Get angles of the NPC. pev(ent, pev_angles, vAngles)
vAngles[1] += 1.0
// Set NPC new angles. set_pev(ent, pev_angles, vAngles)
// Check victim in view cone? if (is_in_viewcone(__int_Entity, vVicOrigin)) { // Make the NPC attack the enemy...
// Think after the attack set_pev(ent, pev_nextthink, get_gametime() + 3.0) return }
// ...
// Think again! set_pev(ent, pev_nextthink, get_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_Entity, EV_ENT_enemy );
static Float:__fl_Angles[3], Float:__fl_AnglesEnd[3], Float:__fl_VictimOrg[3];
entity_get_vector( __int_Victim, 0, __fl_VictimOrg );
setAIMtoORIGIN( __int_Entity, __fl_VictimOrg, __fl_AnglesEnd ); entity_get_vector( __int_Entity, 6, __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_Entity, 6, __fl_Angles ); entity_set_int( __int_Entity, EV_INT_fixangle, 1 );
if (is_in_viewcone(ent, __fl_VictimOrg)) { // Make the NPC attack the enemy...
// Think after the attack set_pev(ent, pev_nextthink, get_gametime() + 3.0) return }
// ...
// Think again! set_pev(ent, pev_nextthink, get_gametime() + 0.1) } public setAIMtoORIGIN( Client, Float:__fl_TOrigin[3], Float:__fl_Aim[3] ) { static Float:__fl_POrigin[3];
entity_get_vector( Client, 0, __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
|