Im trying to make a guided missile (using the fakemeta version of attach view and velocity_by_aim..)
Everything works fine except I want the missile to only fire forwards.
The player start off with their view attached to an entity (that fires that missile), this means that they can't look around at all but moving the mouse still changes something because the missile fires in whatever direction you are 'looking' even though it appeared you were looking straight.
Code:
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
if(ent > 0)
{
set_pev(ent, pev_classname,"rocket")
engfunc(EngFunc_SetModel, ent, "models/rpgrocket.mdl")
engfunc(EngFunc_SetSize, ent, Float:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0})
set_pev(ent, pev_origin,forigin)
set_pev(ent, pev_angles,angles)
new tempangles[3];
set_pev(id, pev_v_angle,angles)
pev(ship, pev_angles, tempangles)
set_pev(id, pev_angles,tempangles)
set_pev(ent, pev_effects,EF_LIGHT)
set_pev(ent, pev_solid,SOLID_TRIGGER)
set_pev(ent, pev_movetype,MOVETYPE_FLY)
set_pev(ent, pev_owner,pilot[id])
velocity_by_aim(pilot[id], rocketspeed, velocity)
set_pev(ent, pev_velocity,velocity)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(22)
write_short(ent)
write_short(smoke)
write_byte(40)
write_byte(4)
write_byte(255)
write_byte(0)
write_byte(0)
write_byte(128)
message_end()
emit_sound(ent, CHAN_WEAPON, "weapons/rocketfire1.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
missile[id]=ent
engfunc(EngFunc_SetView,id,ent)
That's the code to launch the missile. Ship contains the entity id of the original firing entity and angles has the pev_v_angles of the ship..
Code:
new rocketspeed = get_pcvar_num(rocketspeed)
new Float:aimangles[3]
pev(id,pev_v_angle,aimangles)
new Float:setvel[3]
velocity_by_aim(id,rocketspeed,setvel)
set_pev(missile[id],pev_velocity,setvel)
set_pev(missile[id],pev_angles,aimangles)
And that's the steering code.
Since this is getting confusingly long i'll recap.
The missle firing works perfectly and so does the attach views and guiding.
The only problem is that the missle is supposed to fire out straight infront of the 'ship' entity and then let the user steer the missle from there. Instead it will fire out at whatever direction the user is looking..
In the create missile section i've tried setting pev_angles and pev_v_angle for the user but this seems to have no effect...