Page 2 of 2

Re: "Rewinding" Simulations

Posted: Thu Nov 07, 2019 1:41 am
by Norbo
I haven't worked with structs too much, so I'm not entirely sure if there's a difference in this case.
Nope, no difference- using the ref local preserves the original reference rather than copying, so the assignment goes where it needs to.

Re: "Rewinding" Simulations

Posted: Thu Nov 07, 2019 1:51 am
by tomweiland
Norbo wrote:
Thu Nov 07, 2019 1:39 am
Sounds like the object is asleep- many of the BodyReference's functions are intentionally barebones and do not wake the body up automatically. The XML docs for each should mention whether they do or don't. All the direct reference properties and apply impulse functions do not wake the body up. You can set the BodyReference.Awake to true to force the body awake.
I've set the sleep threshold to -1, that has the same effect as manually waking it right?

I'm almost certain that whatever is going wrong is directly related to how states interact with my flotation system...I don't think it's a Bepu issue.
On the one hand that's good because I don't need to take up any more of your time, but it also means I'm pretty much on my own :/

I guess it's time to sit down and spend a few hours debugging :x

As always, thanks for all the help and support :D

Re: "Rewinding" Simulations

Posted: Thu Nov 07, 2019 7:17 pm
by Norbo
I've set the sleep threshold to -1, that has the same effect as manually waking it right?
If the body was initialized with a -1 sleep threshold, then yes, it won't go to sleep. Setting the sleep threshold of a sleeping body to -1 won't wake it up, though.
I guess it's time to sit down and spend a few hours debugging
Good luck! :D

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 1:12 am
by tomweiland
Norbo wrote:
Thu Nov 07, 2019 7:17 pm
Good luck! :D
Thanks! I actually managed to figure it out. It was of course something really stupid on my part, namely the state storing a reference to some positions instead of a copy, which ended up screwing up my buoyancy calculations.

Everything seems to be working great now, except for player movement. Jumping works fine, but when it comes to moving horizontally, it's very "stop-and-go" (it stutters a lot). Considering that my buoyancy system—which applies regular impules—works fine when rewinding time, I'm wondering if the stuttering might be due to the character's constraints in some way.

I'm thinking that since it needs more than 1 timestep to accelerate to full speed, it starts to do that, but the next frame comes along during which we don't have the player's input yet, so I assume that the player isn't pressing any keys (might have to change that and predict based on previous inputs). However, I would've thought that when the simulation is rewound and resimulated—this time with all the inputs—this problem of not having time to accelerate would go away (because there's no more timesteps with no keys pressed, so the player shouldn't be "stopping" anymore).

Maybe there's still something wrong on my end, but I thought I'd ask if you've got any idea about what might be going south here.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 1:53 am
by Norbo
Is the character state being rewound and replayed properly too? The critical ones would be ViewDirection, TargetVelocity, and TryJump. Other than that, nothing springs to mind.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 5:32 am
by tomweiland
Norbo wrote:
Fri Nov 08, 2019 1:53 am
Is the character state being rewound and replayed properly too? The critical ones would be ViewDirection, TargetVelocity, and TryJump. Other than that, nothing springs to mind.
ViewDirection, yes. TargetVelocity and TryJump, nope. I'll take add that tomorrow and see if it fixes it.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 7:28 pm
by tomweiland
Alright so I've added TargetVelocity and TryJump to the states, and the stuttering seems to be gone, however the player now moves along the global axes, instead of his local ones (pressing the forward key causes the player to move in the same direction regardless of which way he is facing).

This was not the case before I added TargetVelocity to the state...is there perhaps some kind of conversion I have to do between global and local space? It might just be on my end again though.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 9:07 pm
by Norbo
The TargetVelocity is in terms of the ViewDirection. The ViewDirection is projected onto the support surface to get the forward movement direction, and a TargetVelocity of (0, 1) will move along that projected forward direction. A TargetVelocity of (1,0) will move to the right of that forward direction. So it sounds like there's an inconsistency of some sort in how the ViewDirection and TargetVelocity are being set- a constant ViewDirection, or a TargetVelocity that is accidentally cancelling out the ViewDirection, or something along those lines.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 9:30 pm
by tomweiland
Norbo wrote:
Fri Nov 08, 2019 9:07 pm
So it sounds like there's an inconsistency of some sort in how the ViewDirection and TargetVelocity are being set- a constant ViewDirection, or a TargetVelocity that is accidentally cancelling out the ViewDirection, or something along those lines.
So does the order in which I set the two affect anything at all? Is the ViewDirection overriden if I set the TargetVelocity afterwards?

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 9:37 pm
by Norbo
Nope- they're raw fields, no logic is performed on set.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 9:49 pm
by tomweiland
So then by "a TargetVelocity that is accidentally cancelling out the ViewDirection" you just mean if I'm setting a TargetVelocity manually, it may not align with the ViewDirection that I've set? That would mean it's on my end again...so probably not an easy fix :cry:

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 10:10 pm
by Norbo
In the sense that it's not aligned with your actual intent, yup. For example, if your goal is to move along the X axis and so set the ViewDirection to (1,0,0) and the TargetVelocity to (1,0), that would result in the character movement basis 'forward' on a flat plane being (1,0,0), but then the world space target velocity would be (0,0,1) because a TargetVelocity of (1,0) will try to move along the direction to the right of the forward direction.

Re: "Rewinding" Simulations

Posted: Fri Nov 08, 2019 10:15 pm
by tomweiland
Norbo wrote:
Fri Nov 08, 2019 10:10 pm
In the sense that it's not aligned with your actual intent, yup. For example, if your goal is to move along the X axis and so set the ViewDirection to (1,0,0) and the TargetVelocity to (1,0), that would result in the character movement basis 'forward' on a flat plane being (1,0,0), but then the world space target velocity would be (0,0,1) because a TargetVelocity of (1,0) will try to move along the direction to the right of the forward direction.
Hmm I see. I guess I'll have to do a bit of digging. Thanks for the help :)