• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/
  • Weve updated the Tripwire Privacy Notice under our Policies to be clearer about our use of customer information to come in line with the EU General Data Protection Regulation (GDPR) rules that come into force today (25th May 2018). The following are highlights of our changes:


    We've incorporated the relevant concepts from the GDPR including joining the EU and Swiss Privacy Shield framework. We've added explanations for why and how Tripwire processes customer data and the types of data that we process, as well as information about your data protection rights.



    For more information about our privacy practices, please review the new Privacy Policy found here: https://tripwireinteractive.com/#/privacy-notice

Can somebody please convert this code into UScript?

YoYoBatty

FNG / Fresh Meat
Dec 17, 2009
3,468
2,503
0
Canada
Here is the code taken from Half Life 2:

Code:
#define MAX_VIEWMODEL_LAG 1.5f
void CBaseViewModel::CalcViewModelLag( Vector& origin, QAngle& angles, QAngle& original_angles )
{
 // Calculate our drift
 Vector forward;
 AngleVectors( angles, &forward, NULL, NULL );
 if ( gpGlobals->frametime != 0.0f )
 {
  Vector vDifference;
  VectorSubtract( forward, m_vecLastFacing, vDifference );
  if ( fabs( vDifference.x ) > MAX_VIEWMODEL_LAG ||
    fabs( vDifference.y ) > MAX_VIEWMODEL_LAG ||
    fabs( vDifference.z ) > MAX_VIEWMODEL_LAG )
  {
   m_vecLastFacing = forward;
  }
  // FIXME:  Needs to be predictable?
  VectorMA( m_vecLastFacing, 5.0f * gpGlobals->frametime, vDifference, m_vecLastFacing );
  // Make sure it doesn't grow out of control!!!
  VectorNormalize( m_vecLastFacing );
  VectorMA( origin, 5, vDifference * -1, origin );
 }
 Vector right, up;
 AngleVectors( original_angles, &forward, &right, &up );
 float pitch = original_angles[ PITCH ];
 if ( pitch > 180.0f )
  pitch -= 360.0f;
 else if ( pitch < -180.0f )
  pitch += 360.0f;
 //FIXME: These are the old settings that caused too many exposed polys on some models
 VectorMA( origin, -pitch * 0.035f, forward, origin );
 VectorMA( origin, -pitch * 0.03f,  right, origin );
 VectorMA( origin, -pitch * 0.02f,  up,  origin);
}
This is the original unmodified code, I've made an attempt at converting it from C++ to UScript before and I was unsuccessful. Can somebody help me out?
 

MetalMedved

FNG / Fresh Meat
Feb 22, 2011
144
38
0
Russia
Try to correct syntax
Code:
var float MAX_VIEWMODEL_LAG;

function CalcViewModelLag( Vector origin, QAngle angles, QAngle original_angles )
{
 // Calculate our drift
 Vector forward, vDifference, right, up;
 float pitch;
 
 MAX_VIEWMODEL_LAG = 1.5f;
 AngleVectors( angles, forward, none, none );
 if ( gpGlobals.frametime != 0.0f )
 {
  VectorSubtract( forward, m_vecLastFacing, vDifference );
  if ( abs( vDifference.x ) > MAX_VIEWMODEL_LAG ||
    abs( vDifference.y ) > MAX_VIEWMODEL_LAG ||
    abs( vDifference.z ) > MAX_VIEWMODEL_LAG )
  {
   m_vecLastFacing = forward;
  }
  // FIXME:  Needs to be predictable?
  VectorMA( m_vecLastFacing, 5.0f * gpGlobals.frametime, vDifference, m_vecLastFacing );
  // Make sure it doesn't grow out of control!!!
  VectorNormalize( m_vecLastFacing );
  VectorMA( origin, 5, vDifference * -1, origin );
 }
 
 AngleVectors( original_angles, forward, right, up );
 pitch = original_angles[ PITCH1 ]; //C++ is case sensitive
 if ( pitch > 180.0f )
  pitch -= 360.0f;
 else if ( pitch < -180.0f )
  pitch += 360.0f;
 //FIXME: These are the old settings that caused too many exposed polys on some models
 VectorMA( origin, -pitch * 0.035f, forward, origin );
 VectorMA( origin, -pitch * 0.03f,  right, origin );
 VectorMA( origin, -pitch * 0.02f,  up,  origin);
}
You should take care about outer functions and structures and resolve c++ case sensitive conflicts
 

YoYoBatty

FNG / Fresh Meat
Dec 17, 2009
3,468
2,503
0
Canada
Okay I figured out what AngleVectors does, but what does:
VectorMA(v,s,b,o) - make b s units long, add to v, result in o
mean? Can you tell me what that means? I want to be sure.

Edit: Here is what I've been able to convert so far thanks to your help :)

Code:
var float MaxViewModelLag;
 
function CalcViewModelLag( vector origin, rotator angles, rotator originalangles )
{
// Calculate our drift
local vector Difference, forward, right, up;
local vector LastFacing;
 
GetAxes( angles, forward, none, none );
if ( Level.TimeSeconds != 0.0 )
{
Difference = LastFacing - forward;
if ( abs( Difference.X ) > MaxViewModelLag || abs( Difference.Y ) > MaxViewModelLag || abs( Difference.Z ) > MaxViewModelLag )
{
LastFacing = forward;
}
VectorMA( LastFacing, 5.0 * Level.TimeSeconds, Difference, LastFacing );
Normal(LastFacing);
VectorMA( origin, 5, Difference * -1, origin );
}
 
GetAxes( originalangles, forward, right, up );
if ( originalangles.pitch > 180.0 )
originalangles.pitch -= 360.0;
else if ( originalangles.pitch < -180.0 )
originalangles.pitch += 360.0;
VectorMA( origin, -originalangles.pitch * 0.035, forward, origin );
VectorMA( origin, -originalangles.pitch * 0.03, right, origin );
VectorMA( origin, -originalangles.pitch * 0.02, up, origin);
}
 
defaultproperties
{
MaxViewModelLag=1.500000
}
I'm not sure if this is right, I still have to figure out what description of VectorMA means.
 
Last edited:

YoYoBatty

FNG / Fresh Meat
Dec 17, 2009
3,468
2,503
0
Canada
Code:
class FDBWeapon extends KFWeapon
 abstract;
var float MaxViewModelLag;
 
// Overridden to take out some UT stuff + Half Life 2 view model lag + new offset and rotation system
simulated event RenderOverlays( Canvas Canvas )
{
 local int m;
 local vector DrawOffset;
     local rotator RollMod;
     local FDBPlayerController Playa;
 local FDBHuman fdbpawn;
 local int leanangle;
 local vector origin, OriginalOrigin;
 local rotator angles, OriginalAngles;
 local rotator angoriginal;
  local vector Difference, forward, right, up;
 local vector LastFacing;
 local vector NULLVector, NULLVector1;
 local float Speed, Diff, Scale;
     if (Instigator == None)
      return;
     // Lets avoid having to do multiple casts every tick - Ramm
     Playa = FDBPlayerController(Instigator.Controller);
 if ( Instigator.Controller != None )
  Hand = Instigator.Controller.Handedness;
 if ( Instigator.Controller == None )
  return;
 angles = Instigator.GetViewRotation();
 angoriginal = Instigator.GetViewRotation();
 origin = PlayerViewOffset + Instigator.EyePosition();
 OriginalOrigin = origin;
 OriginalAngles = angles;
 NULLVector = Vect(0,0,0);
 NULLVector1 = Vect(0,0,0);
  GetAxes( angles, forward, NULLVector, NULLVector1 );
  if ( Level.TimeSeconds != 0.0 )
  {
  Difference = LastFacing - forward;
  Speed = 5.0f;
  Diff = Sqrt(Square(Difference.X) + Square(Difference.Y) + Square(Difference.Z));
  if ( (Diff > MaxViewModelLag) && (MaxViewModelLag > 0.0) )
  {
   Scale = Diff / MaxViewModelLag;
   Speed *= Scale;
  }
  LastFacing = (Speed * Level.TimeSeconds) * Difference;
    Normal(LastFacing);
  origin += -Difference * 5.0;
  }
 
  GetAxes( angoriginal, forward, right, up );
  if ( angoriginal.pitch > 180.0 )
    angoriginal.pitch -= 360.0;
  else if ( angoriginal.pitch < -180.0 )
    angoriginal.pitch += 360.0;
 if ( MaxViewModelLag == 0.0 )
 {
  origin = OriginalOrigin;
  angles = OriginalAngles;
 }
 origin = origin + (-angoriginal.pitch * 0.035) * forward;
 origin = origin + (-angoriginal.pitch * 0.03) * right;
 origin = origin + (-angoriginal.pitch * 0.02) * up;
 DrawOffset = ((0.9/DisplayFOV * 100 * origin) >> angles);
 if ( Instigator.IsLocallyControlled() )
 {
      DrawOffset += Instigator.WeaponBob(BobDamping);
         DrawOffset += Instigator.CameraShake();
 }
 if ((Hand < -1.0) || (Hand > 1.0))
  return;
 // draw muzzleflashes/smoke for all fire modes so idle state won't
 // cause emitters to just disappear
 for (m = 0; m < NUM_FIRE_MODES; m++)
 {
  if (FireMode[m] != None)
  {
   FireMode[m].DrawMuzzleFlash(Canvas);
  }
 }
 //Adjust weapon position for lean
 fdbpawn = FDBHuman(Instigator);
 if (fdbpawn != none && fdbpawn.LeanAmount != 0)
 {
  leanangle += fdbpawn.LeanAmount;
 }
 SetLocation( Instigator.Location + DrawOffset );
 RollMod = angles;
 RollMod.Roll += leanangle;
    SetRotation( RollMod + ZoomRotInterp );
 //PreDrawFPWeapon(); // Laurent -- Hook to override things before render (like rotation if using a staticmesh)
 bDrawingFirstPerson = true;
 Canvas.DrawActor(self, false, false, DisplayFOV);
 bDrawingFirstPerson = false;
}

defaultproperties
{
     MaxViewModelLag=1.500000
}
New code
 
Last edited:

YoYoBatty

FNG / Fresh Meat
Dec 17, 2009
3,468
2,503
0
Canada
If you ever played Half Life 2, you'll notice when you move your gun around it lags independantly of the screen, I'm trying to implent that into killing floor.
 

YoYoBatty

FNG / Fresh Meat
Dec 17, 2009
3,468
2,503
0
Canada
I just figured out that I need to detect that the screen is moving around and setup variables to keep track of DeltaTime, the speed of the screen, the speed of how fast to move the gun, etc.