Download

VinterpTo

Hello. Apologies if this isn’t the right place for this question, but there didn’t seem to be an obvious place to ask.

I’m trying to VInterpTo in UnrealScript, and really struggling with the final parameter InterpSpeed. Here’s the function


native static final function vector VInterpTo( vector Current, vector Target, float DeltaTime, float InterpSpeed );


I’m using it with MoveSmooth.

For example, if my target = Vect(100, 0, 0) - MoveSmooth is relative.

this is in pawn tick code.

So, I do


OriginalPosition = Location;
MoveVector = VInterpTo((Location-OriginalPosition), Target, DeltaTime, ?????);
MoveSmooth(MoveVector);


The (Location - OriginalPosition) gives an offset from location at VInterp start like (2, 0, 0), which is my relative current position to the target. Target is Vect(100,0,0). DeltaTime is coming from Tick(float DeltaTime).

What the heck do I put for InterpSpeed? Is it seconds? Is it an exponential? Is there any way to “fix” this to a time?

I’ve tried it with a bunch of stuff, but the return vector just increases exponentially. I can’t find anything detailing exactly how InterpSpeed controls the curve. Can anyone point me in the right direction please?

I think your problem might be with the first parameter, which should be the current location, not the delta from the current to the original (it depends what you’re trying to accomplish, obviously).

As for the speed, the function uses it like this:


DeltaMove = Dist * FMath::Clamp<float>(DeltaTime * InterpSpeed, 0.f, 1.f);

Where Dist = Target - Current

So it’s not in seconds to arrive, but more like distance traveled per second, relative to how far the target is.

I don’t know how to wield it for precise timed calculations or cm per second though, I’ve been rolling my own solutions for that.

Thank you so much! Also, my code was slightly misleading. I’m setting OriginalPosition earlier. Let me lay it out in more detail.


if(!inited) {
    OriginalPosition = Location;
    inited = true;
}

Target = Vect(100, 0, 0);
MoveVector = VInterpTo((Location-OriginalPosition), Target, DeltaTime, ?????);
MoveSmooth(MoveVector);

Move (and MoveSmooth) are relative to (current) Location, so I needed to work out where, exactly, I was in relation to the target location.

I could equally have done (I think)


Target = OriginalPosition + Vect(100, 0, 0); 
MoveVector = VInterpTo(Location, Target, etc, etc
MoveSmooth(MoveVector - Location);


But, ok, two questions.

  1. Where did you find the code for VInterpTo. It’s defined as native, so I couldn’t dig deeper, and didn’t find it anywhere on the net. I’d love to be able to dig at this stuff for myself, rather than hassling you or others.
  2. If I understand the function correctly, let me break out a specific example.

Let’s assume we’re getting 10 frames per second, so DeltaTime is always 0.1 and InterpSpeed is set to 1.

DeltaMove = Dist * FMath::Clamp<float>(DeltaTime * InterpSpeed, 0.f, 1.f);

At 0.1
DeltaMove = (100-0) * 0.1 * 1 = 10
0.2: (100-10) * 0.1 * 1 = 9
0.3: (100-19) * 0.1 * 1 = 8.1
0.4: (100-27.1) * 0.1 * 1 = 7.29
0.5: (100-34.39) * 0.1 * 1 = 6.561

And so on. So, actually, it’s just inverse exponentially crawling towards the target, and will take (literally) forever to get there.

Can I ask how you’re cooking your own? I’d love to grab hold of something. I’m basically trying to smooth stuff in and out. I’ve tinkered with InterpCurves, but when I apply CIM_CurveAuto, I get massively slowdowns around the curves, even with a few simple points, so I’ve settled on 3x^2-2x^3 which is a clumsy easeinout (Graph Link) for values between 0 and 1.

Ultimately, I’m totally rubbish at animating, and trying to procedurally generate a VTOL aircraft hovering, so throwing a random 100 vector at it every couple of seconds, and having it move around in that fashion (with appropriate pitch and yaw and roll thrown in). It’s ok, but it’s not great. I started to get somewhere with VInterpTo, but only because I threw in a couple of random seeds on each tick to knock it the other way. I’m sure there’s better way.

I’m now thinking I generate a sphere in which it can move, and the closer it is to the centre, the more it can move outwards each tick (individually calculated across three planes), but that starts to get computationally heavy. Any thoughts you have would be most welcomed.

The implementation is in UnrealMath.cpp (FMath::VInterpTo)

I’m not quite grokking what you’re aiming to do, but what I was talking about with my usual implementation is a simple ‘count down’ type of timer or some variation of it. It would count down every tick from the duration I want and I’d normalize it (between 0…1). Sometimes I pass it into FMath::InterpEaseInOut functions as the alpha, depending on the smoothing requirements.

Ah. I’m moddong xcom. I dont think the cpp files are included.

But, basically, create random movement across 3 axes for a hovering aircraft. As if it’s being buffeted by wind.

Without the easeinout, it’s extremely jerky. I ended up doing more or less what you suggested though. The only problem being, move() requires relative vector to current location, so there’s a lot of calculation per tick (calc interp for offset, add to start position, remove current location). I’m thinking about just using setlocation because I’m only moving small distances. But that feels dirty.

I’ve written a probability function which looks at the start position (call it 0,0,1000) and works out how far it is from there. Every half second, it can move rand(25) along all three axes. The further away it is from the origin, the higher the chance it’ll move back towards the centre. So it basically wobbles around in the sky but never gets too far from where it should be. If it’s ever more than 125 units away, it will always move towards the centre.

I throw pitch, roll and yaw into the mix based on move distance to make it a little more realistic.