Hello,
I am trying to keep a solid entity at a certain distance from player's view.
For example: At 150 units in front of player and tracking the distance from player to entity.
So far I am setting the entity velocity to keep it at a distance from player's view, but it works only if I move backwards, not forwards too.
entity_set_aim() function is called on every think of entity.
Code:
Code:
stock entity_set_aim(ent, player)
{
static Float:origin[3], Float:ent_origin[3], Float:angles[3]
pev(player, pev_origin, origin)
pev(ent, pev_origin, ent_origin)
xs_vec_sub(origin, ent_origin, origin)
xs_vec_normalize(origin, origin)
vector_to_angle(origin, angles)
angles[0] = 0.0
if(entity_range(ent, player) > ENT_DISTANCE)
{
set_velocity(ent, angles)
angles[1] -= 90.0
set_pev(ent, pev_angles, angles)
}
}
stock set_velocity(ent, Float:angles[3])
{
static Float: Direction[3]
angle_vector(angles, ANGLEVECTOR_FORWARD, Direction)
xs_vec_mul_scalar(Direction, float(Speed), Direction) // float(-Speed)
set_pev(ent, pev_velocity, Direction)
}
Edit: Just achieved to move entity forwards and backwards by making the Speed positive and negative. But the entity is not staying in front of player.
__________________