atlarge-research / opencraft

Other
5 stars 2 forks source link

Split velocity into force calculation and application #65

Closed jdonkervliet closed 3 years ago

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:45

Split the velocity calculation and application into first calculating the forces acting on an entity and then multiplying these forces with the entities' weight and applying that on the velocity. An example can be found below:

private static final double AIR_DRAG = 0.02;
private static final double WATER_DRAG = 0.25;
private static final double LAVA_DRAG = 0.33;
private static final Vector GRAVITY = new Vector(0.0, -0.1, 0.0);

Vector computeDrag(Material medium, Vector velocity) {

    Vector drag = velocity.clone();
    drag.multiply(-1);

    if (material == Materia.WATER || material == Material.STATIONARY_WATER) {
        drag.multiply(WATER_DRAG);
    } else if (material == Material.LAVA || material == Material.STATIONARY_LAVA) {
        drag.multiply(-LAVA_DRAG);
    } else {
        drag.multiply(-AIR_DRAG);
    }

    return drag;
}

// ...

if (location != null) {

    Vector force = new Vector();

    // Add gravitational pull.
    force.add(GRAVITY);

    // Add drag.
    Block block = location.getBlock();
    Material material = block.getType();
    Vector drag = computeDrag(material, velocity);
    force.add(drag);

    // Apply force to velocity.
    velocity.add(force);
}
jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:48

changed the description

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:54

mentioned in merge request !35

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 22, 2020, 15:02

Armor stands fall through the ground when placed.

Entities don't slow down when falling through cobwebs

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 25, 2020, 19:54

mentioned in merge request !41