hello allieds
As the titile says i am trying to turn sentry gun towards target by PEV_CONTROLLER
here is the picture
https://i.imgur.com/mLULWZM.png
the sentry gun model has two pev_controller
one is for tilt (aiming sentry gun up and down if player is above ground)
one is for rotating on his axis ( see in this video
https://i.imgur.com/Zllr7Gp.mp4)
the code use for turning towards target is below , which rotate the sentry gun on his axis and aim towars its target (taken from JGHG's sentry gun)
PHP Code:
sentry_turntotarget(ent, Float:sentryOrigin[3], target, Float:closestOrigin[3]) {
if (target) {
new name[32]
get_user_name(target, name, 31)
///--- THIS CODE IS FOR TURNING TOWARDS TARGET
new Float:newAngle[3]
entity_get_vector(ent, EV_VEC_angles, newAngle)
new Float:x = closestOrigin[0] - sentryOrigin[0]
new Float:z = closestOrigin[1] - sentryOrigin[1]
new Float:radians = floatatan(z/x, radian)
newAngle[1] = radians * g_ONEEIGHTYTHROUGHPI
if (closestOrigin[0] < sentryOrigin[0])
newAngle[1] -= 180.0
entity_set_float(ent, SENTRY_FL_ANGLE, newAngle[1])
// THIS CODE IS FOR SETTING TILT
new Float:h = closestOrigin[2] - sentryOrigin[2]
new Float:b = vector_distance(sentryOrigin, closestOrigin)
radians = floatatan(h/b, radian)
new Float:degs = radians * g_ONEEIGHTYTHROUGHPI;
// Now adjust EV_BYTE_controller1
// Each degree corresponds to about 100/256 "bytes", = ~0,39 byte / degree (ok this is not entirely true, just tweaked for now with SENTRYTILTRADIUS)
new Float:RADIUS = SENTRYTILTRADIUS // get_cvar_float("sentry_tiltradius");
new Float:degreeByte = RADIUS/256.0; // tweak radius later
new Float:tilt = 127.0 - degreeByte * degs; // 127 is center of 256... well, almost
set_pev(ent, PEV_SENTRY_TILT_TURRET, floatround(tilt))
entity_set_vector(ent, EV_VEC_angles, newAngle)
}
else {
//entity_set_int(ent, SENTRY_INT_FIRE, 0)
//entity_set_edict(ent, SENTRY_ENT_TARGET, 0)
//client_print(0, print_chat, "%d: I don't see anyone.", ent)
}
}
so can anybody help me to use the pev_controller instead of
PHP Code:
entity_set_vector(ent, EV_VEC_angles, newAngle)
for turning the sentry gun and aim it to target
i am weak in maths so can anybody help me ?
__________________