Simpler bouncing? Thanks @K1521

This commit is contained in:
grimmauld 2021-03-31 21:18:33 +02:00
parent 65d21c374b
commit 3cc8291b72

View file

@ -213,6 +213,7 @@ public class ContraptionCollider {
totalResponse = VecHelper.rotate(totalResponse, yawOffset, Axis.Y); totalResponse = VecHelper.rotate(totalResponse, yawOffset, Axis.Y);
collisionNormal = rotationMatrix.transform(collisionNormal); collisionNormal = rotationMatrix.transform(collisionNormal);
collisionNormal = VecHelper.rotate(collisionNormal, yawOffset, Axis.Y); collisionNormal = VecHelper.rotate(collisionNormal, yawOffset, Axis.Y);
collisionNormal = collisionNormal.normalize();
collisionLocation = rotationMatrix.transform(collisionLocation); collisionLocation = rotationMatrix.transform(collisionLocation);
collisionLocation = VecHelper.rotate(collisionLocation, yawOffset, Axis.Y); collisionLocation = VecHelper.rotate(collisionLocation, yawOffset, Axis.Y);
rotationMatrix.transpose(); rotationMatrix.transpose();
@ -240,17 +241,12 @@ public class ContraptionCollider {
boolean hasNormal = !collisionNormal.equals(Vec3d.ZERO); boolean hasNormal = !collisionNormal.equals(Vec3d.ZERO);
boolean anyCollision = hardCollision || temporalCollision; boolean anyCollision = hardCollision || temporalCollision;
if (bounce > 0 && hasNormal && anyCollision) { if (bounce > 0 && hasNormal && anyCollision && bounceEntity(entity, collisionNormal, contraptionEntity, bounce)) {
collisionNormal = collisionNormal.normalize();
Vec3d newNormal = collisionNormal.crossProduct(collisionNormal.crossProduct(entityMotionNoTemporal))
.normalize();
if (bounceEntity(entity, newNormal, contraptionEntity, bounce)) {
entity.world.playSound(playerType == PlayerType.CLIENT ? (PlayerEntity) entity : null, entity.world.playSound(playerType == PlayerType.CLIENT ? (PlayerEntity) entity : null,
entity.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_SLIME_BLOCK_FALL, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_SLIME_BLOCK_FALL,
SoundCategory.BLOCKS, .5f, 1); SoundCategory.BLOCKS, .5f, 1);
continue; continue;
} }
}
if (temporalCollision) { if (temporalCollision) {
double idealVerticalMotion = motionResponse.y; double idealVerticalMotion = motionResponse.y;
@ -280,7 +276,6 @@ public class ContraptionCollider {
} }
if (bounce == 0 && slide > 0 && hasNormal && anyCollision && rotation.hasVerticalRotation()) { if (bounce == 0 && slide > 0 && hasNormal && anyCollision && rotation.hasVerticalRotation()) {
collisionNormal = collisionNormal.normalize();
Vec3d motionIn = entityMotionNoTemporal.mul(0, 1, 0) Vec3d motionIn = entityMotionNoTemporal.mul(0, 1, 0)
.add(0, -.01f, 0); .add(0, -.01f, 0);
Vec3d slideNormal = collisionNormal.crossProduct(motionIn.crossProduct(collisionNormal)) Vec3d slideNormal = collisionNormal.crossProduct(motionIn.crossProduct(collisionNormal))
@ -338,35 +333,14 @@ public class ContraptionCollider {
return false; return false;
if (entity.bypassesLandingEffects()) if (entity.bypassesLandingEffects())
return false; return false;
if (normal.equals(Vec3d.ZERO))
return false;
Vec3d contraptionVec = Vec3d.ZERO;
Vec3d contactPointMotion = contraption.getContactPointMotion(entity.getPositionVec()); Vec3d contactPointMotion = contraption.getContactPointMotion(entity.getPositionVec());
Vec3d motion = entity.getMotion() Vec3d motion = entity.getMotion().subtract(contactPointMotion);
.subtract(contactPointMotion); Vec3d deltav = normal.scale(factor*2*motion.dotProduct(normal));
if (deltav.dotProduct(deltav) < 0.1f)
Vec3d v2 = motion.crossProduct(normal)
.normalize();
if (v2 != Vec3d.ZERO)
contraptionVec = normal.scale(contraptionVec.dotProduct(normal))
.add(v2.scale(contraptionVec.dotProduct(v2)));
else
v2 = normal.crossProduct(normal.add(Math.random(), Math.random(), Math.random()))
.normalize();
Vec3d v3 = normal.crossProduct(v2);
motion = motion.subtract(contraptionVec);
Vec3d lr = new Vec3d(factor * motion.dotProduct(normal), -motion.dotProduct(v2), -motion.dotProduct(v3));
if (lr.dotProduct(lr) > 1 / 16f) {
Vec3d newMot = contactPointMotion.add(normal.x * lr.x + v2.x * lr.y + v3.x * lr.z,
normal.y * lr.x + v2.y * lr.y + v3.y * lr.z, normal.z * lr.x + v2.z * lr.y + v3.z * lr.z);
entity.setMotion(newMot);
return true;
}
return false; return false;
entity.setMotion(entity.getMotion().subtract(deltav));
return true;
} }
public static Vec3d getWorldToLocalTranslation(Entity entity, AbstractContraptionEntity contraptionEntity) { public static Vec3d getWorldToLocalTranslation(Entity entity, AbstractContraptionEntity contraptionEntity) {