Closed Ali-RS closed 5 years ago
I'm thinking PositionTransition maybe shouldn't even have this method on it... else it needs to be much more complicated to deal with whether the caller wants to clamp or just return null, etc..
Not sure anymore what velocity is being used for in this case but it would have been easy enough for this code to calculate it from what it had.
Also the name itself is not accurate since the time has to be inverted for it to even count as a velocity. At best it's a frame delta unless we build the time calculation into the call.
Oh... this is your code. Are you using it for Mob animation? If so you may want to use the amount the spatial has actually moved instead. Hard to say. (It's what I do but I know there will be occasional glitches with either approach.)
Yep, it's my code. and yes I am using it for MobAnimationState and I am using MobPositionAdapter as a way to let my tweens to have access to entity's velocity.
Based on your comment and because my game is networked game I thought to use PositionTransition which should solve this problem out of the box.
// Because we aren't interpolating over known good physics frames
// like we would in a network app, we have the possibility of seeing
// the same position in two visual frames even if the object is moving.
If so you may want to use the amount the spatial has actually moved instead. Hard to say. (It's what I do but I know there will be occasional glitches with either approach.)
Okay I will use Spatial to calculate velocity just like you did in MobAnimationState.
I mean, it solves one problem but presents another... you might be getting the interpolated position at the very beginning or very end of a network frame. It's not at all clear to me that the velocity of that network frame should apply equally to the animation speed over the whole frame. But maybe that's just my paranoia.
In the end, you will want some kind of speed smoothing anyway. I don't remember exactly what I put that comment so I don't know if it's related to the low pass filtering or not.
Actually, that comment seems only related to non PositionTransition code where we only see discrete jumps in position since we aren't interpolating. It's unrelated to when spatials are sampled and more about catching two visual frames before a new physics frame.
In a network app or even in a non-network app properly using PositionTransition, it's not an issue.
Yep, it wont be an issue for me because my spatials are already getting interpolated with PositionTransition. Actually that getFrameVelocity() tricked me and I thought it's just easy to get from there instead of calculation it from spatial in visual frame.
I am going to base it on spatial data as you said.
So I think I can close this.
@pspeed42 in case you want you can reopen this if you think that NullPointerException should be handled or getFrameVelocity() should be removed in PositionTransition .
I may just remove the method or rename it. I think it's probably not used... I'm checking my own code.
happens in updateSpatial method in ModelViewstate
I can work around it by adding a check
if (trans.getStartTime() > 0)
@pspeed42 should
PositionTransition
take care of it internally ?