Entity.LinearVelocity != 0 but entity not moving

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Entity.LinearVelocity != 0 but entity not moving

Post by JusTiCe8 »

Hi Norbo,

I have two questions, one as the title said, I have a dynamic entity (a sphere) and, in a maze, when the sphere is blocked by a wall, the LinearVelocity in the related direction stay as it was before (ex linVel.Z = -6.6 when the sphere stop moving).
Is this the expected behavior ? If so, how can I get the actual velocity (knowing a non moving entity should have a velocity = 0 in the 3 ways) ?
Another example could be: I get a car and in front of a wall, the speed is not zero despite car not moving at all, how to get the right speed to display on the speedometer ?

(I can send you my solution if you want).

2nd question: does a CompoundShape made of a List<CompoundShapeEntry> is better when it has less components or not ?
(rephrased: are all the members making a CompoundShape object are merged in some phase ?)
I build walls of a maze using 1x1x1 boxes, and I just wonder if it wouldn't be better to merge walls when possible into longer/wider boxes, so instead of 4 1x1x1 boxes, I can have a 1 1x1x4 box for example.
Doing such a merge doesn't look very easy so I prefer to ask 1st what's best in order to save some effort doing a "non-optimization" :).
(I create a dynamic entity later on from the CompoundShape)

Thanks a lot.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by Norbo »

I have a dynamic entity (a sphere) and, in a maze, when the sphere is blocked by a wall, the LinearVelocity in the related direction stay as it was before (ex linVel.Z = -6.6 when the sphere stop moving).
Is this the expected behavior ? If so, how can I get the actual velocity (knowing a non moving entity should have a velocity = 0 in the 3 ways) ?
That's not expected behavior. Is the measurement being made after the LinearVelocity is being manually set each frame?

Note that an entity that appears to be stationary may still have very small nonzero velocity (e.g. 0.00001), so avoid floating point comparisons with zero. Also, note that a deactivated entity may still have a velocity below the deactivation threshold. Unless you changed that threshold, -6.6 is a couple of orders of magnitude too high to be explained by deactivation.
2nd question: does a CompoundShape made of a List<CompoundShapeEntry> is better when it has less components or not ?
(rephrased: are all the members making a CompoundShape object are merged in some phase ?)
Having less entries in a compound will tend to make it faster. There is no automatic merging.

I would suggest testing the performance without this optimization first to see if it's fast enough. My guess is that it will be.
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by JusTiCe8 »

Norbo wrote: That's not expected behavior. Is the measurement being made after the LinearVelocity is being manually set each frame?

Note that an entity that appears to be stationary may still have very small nonzero velocity (e.g. 0.00001), so avoid floating point comparisons with zero. Also, note that a deactivated entity may still have a velocity below the deactivation threshold. Unless you changed that threshold, -6.6 is a couple of orders of magnitude too high to be explained by deactivation.
Good point !
space update is done in XNA game update method
sphere linear velocity is read in XNA game draw method (which is allegedly called AFTER update, I use allegedly because for now, I just rely on this fact without actually checking it by myself) and displayed on screen.

I use this for the display:

Code: Select all

string.Format("\nBallPos X={0:F1} Y={1:F1} Z={2:F1}\nspeed X={0:F2} Y={1:F2} Z={2:F2}", ball_test.Position.X, ball_test.Position.Y, ball_test.Position.Z, ball_test.LinearVelocity.X, ball_test.LinearVelocity.Y, ball_test.LinearVelocity.Z);
Norbo wrote: Having less entries in a compound will tend to make it faster. There is no automatic merging.

I would suggest testing the performance without this optimization first to see if it's fast enough. My guess is that it will be.
ok thanks. I'll see in due time.
(for now I have only 91 boxes in my test maze, which is of course a piece of cake for BEPU ;) and my hardware ! )
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by JusTiCe8 »

As you may have forgot the linear velocity issue, here is a pic of it ("speed" = all 3 components of the lin.vel.):

Image

Ball obviously doesn't move at all (data gathered on the draw call of the XNA game)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by Norbo »

Is the ball controlled in any way? Do you ever set the ball's linear velocity yourself? If so, is it being set after the Space.Update? If so, the velocity read in draw will always pick up that written value, not the solver-computed value that got overwritten.

To avoid this, either read the velocity between the Space.Update and manual velocity set, or put the manual velocity set before the Space.Update so that the draw (which does occur after the update(s)) will see the solver-computed value. If it's based on user input, putting the manual velocity set before Space.Update will also remove a frame of latency, since the simulation feels the change sooner.
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by JusTiCe8 »

Norbo wrote:Is the ball controlled in any way? Do you ever set the ball's linear velocity yourself? If so, is it being set after the Space.Update? If so, the velocity read in draw will always pick up that written value, not the solver-computed value that got overwritten.

To avoid this, either read the velocity between the Space.Update and manual velocity set, or put the manual velocity set before the Space.Update so that the draw (which does occur after the update(s)) will see the solver-computed value. If it's based on user input, putting the manual velocity set before Space.Update will also remove a frame of latency, since the simulation feels the change sooner.
I didn't move the ball in the code, ball only move due to the gravity (set to -30) applied to it when the maze angle change.
Important notice (or not): I use parallel code, took as-is from the demo (so I may have 8 threads (i7-4700HQ CPU)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by Norbo »

Oop, I just took a closer look. In that picture, the output speed and position seem suspiciously similar, almost as if they're the same values formatted differently :P
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Entity.LinearVelocity != 0 but entity not moving

Post by JusTiCe8 »

Norbo wrote:Oop, I just took a closer look. In that picture, the output speed and position seem suspiciously similar, almost as if they're the same values formatted differently :P
:mrgreen: could you believe it ?
the format string was:

Code: Select all

Pos X={0:F1} Y={1:F1} Z={2:F1}\nspeed X={[b][u]0[/u][/b]:F2} Y={[b][u]1[/u][/b]:F2} Z={[b][u]2[/u][/b]:F2}
Shame on me :oops: .

Thanks for pointing the obvious I have missed.
Post Reply