DOD:Source Weapon Fire View Move

Please don't post here unless its in response to an existing topic. New discussion is to be shared in the other forums.

DOD:Source Weapon Fire View Move

Postby Jorg40 » Sat Dec 30, 2006 6:19 pm

I know this is not so hard. But hard for me.

What I want to achieve, is when you fire a weapon the player view shakes up a bit, and stay there. So if you spray the player view will at the end be looking straight up.

This is the AR2 Kick.
Code: Select all
void CWeaponAR2::AddViewKick( void )
{
   #define   EASY_DAMPEN         0.5f
   #define   MAX_VERTICAL_KICK   8.0f   //Degrees
   #define   SLIDE_LIMIT         5.0f   //Seconds
   
   //Get the view kick
   CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );

   if (!pPlayer)
      return;

   DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT );
}


This just randomly moves more more the player view after how many shots he fires.

Any idea on how to do it? :wink:
Would help alot.

Regards.
Jorg40
 

Postby steven_m64 » Sun Dec 31, 2006 6:13 pm

i spent a long time and tried many different methods to try and pull off that effect correctly and none of the original viewkick code will work for what you want to pull off.

also any new direct view editing code placed in any of the weapons view kick functions will produce prediction errors causing the view to jerk wildly witch the only wait to stop that is to use engines InPrediction() check But the problem is NONE of the weapons view code is ever called when not in prediction.

you have to make a function in the weapon class thats soemthing like WeaponKick() that checks:
1. if your in prediction do nothing.
2. when not in prediction check if the weapon is in the process of being fired or needs to have recoil applied then apply a very small slight movement/kick since this function will be called many times each second.

place a set of commands in the client code that calls that function on the users current weapon.

---


the method i used was slightly different as i created a function called Recoil() in the weapon class that returns the amount of recoil to be applied in that call in a vector.
in the players client sided CreateMove that checks the players current weapon for a bool named m_bRecoil and if its true it will add the weapons current recoil ammount to the players current viewangles. heres a small cut from my code:
Code: Select all
   if ( !prediction->InPrediction() )
   {
      CWeaponSDKBase *wpn = dynamic_cast< CWeaponSDKBase* >( GetActiveWeapon() );
      if ( wpn && wpn->m_bRecoil )
      {
         VectorAdd( pCmd->viewangles, wpn->Recoil(), pCmd->viewangles );
         engine->SetViewAngles( pCmd->viewangles );
      }
   }
   BaseClass::CreateMove( flInputSampleTime, pCmd );


this methods to get it to work correctly are a bit evil as it would be best to keep all of this within the weapon itself but that would require a extensive code rewrite.
steven_m64
Retarded Coder
 
Posts: 25
Joined: Tue Nov 21, 2006 7:41 am

Postby Jorg40 » Mon Jan 01, 2007 5:24 am

So the VectorAdd just add a vector to player view when fired. Sound like the thing im looking for.

Anyhow I have no idea on how to get it done.

I've looked trough codes, and prediction seem a bith hard in my eyes.
Jorg40
 

Postby steven_m64 » Tue Jan 02, 2007 4:16 am

i gave you all the info your really need.

if you still don't know what to do, its best you continue learning more code.
steven_m64
Retarded Coder
 
Posts: 25
Joined: Tue Nov 21, 2006 7:41 am

Postby Jorg40 » Tue Jan 02, 2007 12:44 pm

Yeah understanded it now, reading too fast.
Jorg40
 


Return to Unsorted Old Posts

Who is online

Users browsing this forum: No registered users and 1 guest

cron