notgiven688 / jitterphysics2

Fast, simple, and dependency-free physics engine written in C# with a clear and user-friendly API.
MIT License
226 stars 19 forks source link

Is jitterPhysics2 deterministic? Have you considered using fixed-point numbers? #181

Open dannisliang opened 1 month ago

dannisliang commented 1 month ago

Is jitterPhysics2 deterministic? Have you considered using fixed-point numbers?

notgiven688 commented 1 month ago

No, it is not deterministic at the moment. Fixed-point will be very slow.

Determinism should be possible to achieve for single-threaded runs. At the moment we have some "pseudo-random" code-paths which break determinism even on the same computer. I will have a look into this.

long1752062104 commented 1 month ago

jitterPhysics2 是确定性的吗?您是否考虑过使用定点数?

This is the deterministic warehouse address for JitterPhysics2 https://gitee.com/leng_yue/jitterphysics2fixed/tree/master/

notgiven688 commented 1 month ago

@long1752062104 Interesting! Will check it out later. How is the performance?

long1752062104 commented 1 month ago

@long1752062104有趣!稍后会查看。性能如何?

The performance is good, but there are still some issues with the character's movement. You can add a character collider, which would be perfect

long1752062104 commented 1 month ago

@long1752062104有趣!稍后会查看。性能如何?

性能不错,但角色的移动还是有些问题。如果能加一个角色碰撞器就完美了

This is my problem, adding the following code will make it normal

` public void SetLinearInput(JVector deltaMove) { if (!CanJump(out var floor, out JVector hitpoint)) { return; }

deltaMove *= 3.0f;

float deltaMoveLen = deltaMove.Length();

JVector bodyVel = Body.Velocity;
bodyVel.Y = 0;

//float bodyVelLen = bodyVel.Length();

if (deltaMoveLen > 0.01f)
{
    //if (bodyVelLen < 5f)
    {
        var force = JVector.Transform(deltaMove, Body.Orientation) * 10.0f;

        //Body.AddForce(force);
        Body.Velocity = force;

        // follow Newton's law (for once) and add a force
        // with equal magnitude in the opposite direction.
        floor!.AddForce(-force, Body.Position + hitpoint);
    }
}
else 
{
    Body.Velocity = JVector.Zero;
}

} `