For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Smooth transition from vector to vector?

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
Rocky
OldUnreal Member
Posts: 99
Joined: Mon Nov 18, 2013 9:21 am

Smooth transition from vector to vector?

Post by Rocky »

Hi.

Is it possible to have smooth transition between two vectors? I am trying to implement aiming sights in unreal, where player holds the AltFire button and the PlayerViewOffset of weapon smoothly translates to a new vector.

I tried to do this and it kind of works though not smoothly as expected.

Code: Select all

class ASMDTest extends ASMD;


//summon ironsighttest.asmdtest

var() vector AimSightOffset;
var bool bAltIronSight;
var float DT;

replication
{
      reliable if(ROLE == ROLE_Authority)
            AimSightOffset;
}

function PlayFiring()
{
      Owner.PlaySound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*4.0);
      PlayAnim('Fire1', 5.5,0.05);
}

simulated function PostRender(Canvas C)
{
      Super.PostRender(C);

      C.Font = Font'SmallFont';
      C.Style = ERenderStyle.STY_Translucent;
      C.DrawColor.R = 255;
      C.DrawColor.G = 255;
      C.DrawColor.B = 255;

      C.SetPos(0, 0.2 * C.ClipY);
      C.DrawText("bAltIronSight: "@bAltIronSight);
      C.SetPos(0, 0.25 * C.ClipY);
      C.DrawText("AimTime: "@AimTime);
      C.SetPos(0, 0.3 * C.ClipY);
      C.DrawText("PlayerViewOffset.X: "@PlayerViewOffset.X);
      C.SetPos(0, 0.32 * C.ClipY);
      C.DrawText("PlayerViewOffset.Y: "@PlayerViewOffset.Y);
      C.SetPos(0, 0.34 * C.ClipY);
      C.DrawText("PlayerViewOffset.Z: "@PlayerViewOffset.Z);

      if(!bAltIronSight)
            return;

      if(ClientIsAiming())
      {
            /*PlayerViewOffset.X = AimSightOffset.X;
            PlayerViewOffset.Y = AimSightOffset.Y;
            PlayerViewOffset.Z = AimSightOffset.Z;*/

            if(PlayerViewOffset.X = default.PlayerViewOffset.Y)
                  PlayerViewOffset.Y = default.PlayerViewOffset.Y;
            else
                  PlayerViewOffset.Y += 500 * DT;

            //PlayerViewOffset.Y = default.PlayerViewOffset.Y;
            PlayerViewOffset.Z = default.PlayerViewOffset.Z;

            FireOffset.Y = -default.FireOffset.Y;
      }
}

function Tick(float DeltaTime)
{
      DT = DeltaTime;
}

simulated function bool ClientIsAiming()
{
      return (bAltIronSight &&
                  Owner.IsA('PlayerPawn') &&
                  PlayerPawn(Owner).bAltFire!=0 && 
                  GetStateName()!='Active' &&
                  GetStateName()!='DownWeapon');
}

function AltFire(float Value)
{
      If (!Owner.IsA('PlayerPawn'))
      {
            Pawn(Owner).bFire = 1;
            Pawn(Owner).bAltFire = 0;
            Global.Fire(0);
      }
      if (!bAltIronSight)
            PlayerPawn(Owner).bAltFire = 0;

      if(!IsInState('Idle'))
            GoToState('Idle');
}

defaultproperties
{
      bAltIronSight=True
      PickupAmmoCount=5000
      AimSightOffset=(X=250.500000,Y=0.000000,Z=-100.000000)
      PlayerViewOffset=(X=350.500000,Y=150.800000,Z=-200.000000)
}
Does anyone have any better solution or hints for this?
Thanks.
Last edited by Rocky on Mon Apr 30, 2018 12:46 pm, edited 1 time in total.
User avatar
yrex .
OldUnreal Member
Posts: 291
Joined: Wed May 06, 2015 6:46 am

Re: Smooth transition from vector to vector?

Post by yrex . »

Code: Select all

function vector VSmerp(float alpha, vector A, vector B)
{
      alpha = FMin(1,FMax(alpha,0));
      
      // extra smooth
      alpha = -cos(alpha*3.1415926535)/2+0.5;
      
      return B*alpha + A*(1-alpha);
}
Not tested.
My work | contact: ampoyrex at wp dot pl
User avatar
Rocky
OldUnreal Member
Posts: 99
Joined: Mon Nov 18, 2013 9:21 am

Re: Smooth transition from vector to vector?

Post by Rocky »

Thank you very much. Your code is working the way I wanted.
User avatar
Shivaxi
OldUnreal Member
Posts: 2232
Joined: Wed Mar 08, 2006 4:43 pm

Re: Smooth transition from vector to vector?

Post by Shivaxi »

Code looks similar to how Bleeder and I did our ironsights aiming function in RLCoop or even our EarthWepzFoRealz mod, even using the same names like ClientIsAiming haha.  But we had it with a smooth transition already.  I don't know how it worked though, would have to ask Bleeder since he coded that.
Last edited by Shivaxi on Thu May 03, 2018 7:45 pm, edited 1 time in total.
Image  Image
User avatar
Rocky
OldUnreal Member
Posts: 99
Joined: Mon Nov 18, 2013 9:21 am

Re: Smooth transition from vector to vector?

Post by Rocky »

Code looks similar to how Bleeder and I did our ironsights aiming function in RLCoop or even our EarthWepzFoRealz mod, even using the same names like ClientIsAiming haha.  But we had it with a smooth transition already.  I don't know how it worked though, would have to ask Bleeder since he coded that.
For ClientIsAiming I asked Gizzy to use his code from CS227 when I was porting CS 1.6 weapons and CS:S weapons to UT and he gave me permission to use it.
I tried EarthWepzFoRealz mod and I didn't see any transition from hip to aiming sight.
Last edited by Rocky on Fri May 04, 2018 5:06 am, edited 1 time in total.
User avatar
Shivaxi
OldUnreal Member
Posts: 2232
Joined: Wed Mar 08, 2006 4:43 pm

Re: Smooth transition from vector to vector?

Post by Shivaxi »

Code looks similar to how Bleeder and I did our ironsights aiming function in RLCoop or even our EarthWepzFoRealz mod, even using the same names like ClientIsAiming haha.  But we had it with a smooth transition already.  I don't know how it worked though, would have to ask Bleeder since he coded that.
For ClientIsAiming I asked Gizzy to use his code from CS227 when I was porting CS 1.6 weapons and CS:S weapons to UT and he gave me permission to use it.
I tried EarthWepzFoRealz mod and I didn't see any transition from hip to aiming sight.
Yeah we were working off of Gizzy's code as well for EarthWeps haha, hence the same variable names, that's what I meant.  We never got the smooth transition into EarthWepz but it IS in RLCoop right now (on a server can look stuttery though with our method, single player is smooth).
Last edited by Shivaxi on Fri May 04, 2018 6:46 am, edited 1 time in total.
Image  Image

Return to “UScript Board”