AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Entity Angles (https://forums.alliedmods.net/showthread.php?t=54176)

pRED* 04-18-2007 23:50

Entity Angles
 
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...

Emp` 04-19-2007 01:45

Re: Entity Angles
 
edit: one sec, rethinking.

Try using the ships angles into angle_vector to get an initial velocity, instead of using velocity_by_aim.

pRED* 04-20-2007 22:18

Re: Entity Angles
 
Initial Vector is fine..

i've modified the missile steering code to this..

Code:
        new button, oldbutton         button = pev(id,pev_button)         oldbutton = pev(id,pev_oldbuttons)         new Float:aimangles[3]         pev(id,pev_v_angle,aimangles)         set_pev(missile[id],pev_angles,aimangles)             if((button & IN_ATTACK) && !(oldbutton & IN_ATTACK))         {             new apache_rocketspeed = get_pcvar_num(rocketspeed)             new Float:setvel[3]             velocity_by_aim(id,apache_rocketspeed,setvel)             set_pev(missile[id],pev_velocity,setvel)                     }

Which works as intended, you can rotate the missile around freely with the mouse and when you click it changes to travel in the direction you are looking.

It also fires dead straight from the ship but the problem is still the your current looking direction is the same as previous.
So for example you fire a missile and your looking out the back of it as it fires along straight. Spinning the mouse around so you look forward and then start clicking to guide it and it works fine..

Since it is the players angle the sets the angle of the missile entity I'm guessing I'd need to set the players angle to straight infront. But I'm pretty sure I've done that and it doesn't help..

pRED* 04-22-2007 21:04

Re: Entity Angles
 
dw.

set_pev(id,pev_fixangle,1) fixed it..


All times are GMT -4. The time now is 06:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.