Page 1 of 1

When change direction sometime it jump.

Posted: Tue Dec 03, 2019 10:30 am
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

Re: When change direction sometime it jump.

Posted: Tue Dec 03, 2019 7:05 pm
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.

Re: When change direction sometime it jump.

Posted: Wed Dec 04, 2019 3:47 am
by parapoohda
Thank you for the answer.
I will look int it. :D :D :D

Re: When change direction sometime it jump.

Posted: Wed Dec 04, 2019 3:57 am
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

Re: When change direction sometime it jump.

Posted: Wed Dec 04, 2019 6:58 pm
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))

Re: When change direction sometime it jump.

Posted: Thu Dec 05, 2019 10:42 am
by parapoohda
Thank you. I will try it out.

Re: When change direction sometime it jump.

Posted: Sat Dec 07, 2019 6:44 am
by parapoohda
It seem only jump when it is lag like when massive debug log. Maybe it is lag.

Re: When change direction sometime it jump.

Posted: Sun Dec 08, 2019 11:27 pm
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.

Re: When change direction sometime it jump.

Posted: Mon Dec 09, 2019 4:53 am
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);
            }
        }

Re: When change direction sometime it jump.

Posted: Mon Dec 09, 2019 6:53 pm
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.

Re: When change direction sometime it jump.

Posted: Tue Dec 10, 2019 6:18 am
by parapoohda
Thank you.