When change direction sometime it jump.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

When change direction sometime it jump.

Post by parapoohda »

1 When I change direction sometime it jump I try to replicate it and find it cause.But I can't. Maybe it is relate with my maximum horizontal force 100

Code: Select all

 
 characterInput = new CharacterInput(characterCTs, bodyHandle, simulation, this.startPosition, new Capsule(0.5f, 1f), 0.1f, 1f, 1, 100, 6, 4, MathF.PI * 0.4f); 
2 When change direction it is slow
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: When change direction sometime it jump.

Post by Norbo »

1) I'd probably need more information/a reproducing example to figure out the jumping. If it's actually a character jump, could there be something somewhere incorrectly updating the character's TryJump status?
2) It looks like the maximum horizontal force is 1, not 100. With a mass of 1, then acceleration would be 1 unit per second per second- pretty slow for that size character.
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: When change direction sometime it jump.

Post by parapoohda »

Thank you for the answer.
I will look int it. :D :D :D
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: When change direction sometime it jump.

Post by parapoohda »

sorry I add body handle to function so my maximum horizontal force is move backward many position.

Code: Select all

 public CharacterInput(CharacterControllers characters, int bodyHandle, Simulation simulation, System.Numerics.Vector3 initialPosition, Capsule shape,
                float speculativeMargin, float mass, float maximumHorizontalForce, float maximumVerticalGlueForce,
                float jumpVelocity, float speed, float maximumSlope = MathF.PI * 0.25f)
It seem it jump or run pass object very fast after try to collide object many time. Not sure though
update :
no its seem jump event is no object
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: When change direction sometime it jump.

Post by Norbo »

It may be related to ghost collisions, though those tend to be pretty darn rare with a speculative margin of 0.1. You could try reducing the speculative margin further to a small nonzero value (0.01 or something) to see if it becomes rarer. The speculative margin of a pair of objects is the larger of the two collidable's margin, though, so you'd have to adjust both the character and whatever it's colliding with. Be careful about going too small- it might hurt collision detection quality. You may want to only modify the margin of the character and static objects, leaving other dynamics with a more generous margin.

If a smaller margin does seem to help, you could try using a continuous collision detection mode on the character to help avoid penetration. When creating the body for the character, you can expand the collidable description:

Code: Select all

new CollidableDescription(shapeIndex, speculativeMargin, ContinuousDetectionSettings.Continuous(1e-3f, 1e-3f))
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: When change direction sometime it jump.

Post by parapoohda »

Thank you. I will try it out.
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: When change direction sometime it jump.

Post by parapoohda »

It seem only jump when it is lag like when massive debug log. Maybe it is lag.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: When change direction sometime it jump.

Post by Norbo »

Just to check, the Simulation.TimeStep is being called with a constant time, right? If significantly varying values are provided from frame to frame, it could cause instability.
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: When change direction sometime it jump.

Post by parapoohda »

no it is not constant. it is dt.

Code: Select all

public void LoopThread()
        {
            var expectedTicks = 15 * TICKS_PER_MILLISECOND;
            var debt = 0L;
#if DEBUG
            var physicsTicks = 0L;
#endif
            var useTicks = 0L;
            var startTicks = 0L;
            while (isRun)
            {
                startTicks = DateTime.Now.Ticks;
#if DEBUG
                physicsTicks += expectedTicks + debt;
#endif
                long tickPlusDebt = expectedTicks + debt;
                float dt = (float)tickPlusDebt / TICKS_PER_SECOND;

                onUpdate(dt);

                useTicks = DateTime.Now.Ticks - startTicks;
                if (expectedTicks > useTicks)
                {
                    Thread.Sleep((int)((expectedTicks - useTicks) / TICKS_PER_MILLISECOND));
                }
                debt = expectedTicks - (DateTime.Now.Ticks - startTicks);
            }
        }
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: When change direction sometime it jump.

Post by Norbo »

The dt value passed Simulation.Timestep should ideally be a constant value. Using the elapsed time directly is pretty much guaranteed to cause nasty stability problems. It's fine to use a variable step for other logic if desired, but simulation timesteps should only be dispatched with a well-controlled timestep. That generally means accumulating elapsed time and consuming it by dispatching updates of fixed length.
parapoohda
Posts: 92
Joined: Fri May 31, 2019 6:30 am

Re: When change direction sometime it jump.

Post by parapoohda »

Thank you.
Post Reply