mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
Simpler bouncing? Thanks @K1521
This commit is contained in:
parent
65d21c374b
commit
3cc8291b72
1 changed files with 12 additions and 38 deletions
|
@ -213,6 +213,7 @@ public class ContraptionCollider {
|
|||
totalResponse = VecHelper.rotate(totalResponse, yawOffset, Axis.Y);
|
||||
collisionNormal = rotationMatrix.transform(collisionNormal);
|
||||
collisionNormal = VecHelper.rotate(collisionNormal, yawOffset, Axis.Y);
|
||||
collisionNormal = collisionNormal.normalize();
|
||||
collisionLocation = rotationMatrix.transform(collisionLocation);
|
||||
collisionLocation = VecHelper.rotate(collisionLocation, yawOffset, Axis.Y);
|
||||
rotationMatrix.transpose();
|
||||
|
@ -240,16 +241,11 @@ public class ContraptionCollider {
|
|||
boolean hasNormal = !collisionNormal.equals(Vec3d.ZERO);
|
||||
boolean anyCollision = hardCollision || temporalCollision;
|
||||
|
||||
if (bounce > 0 && hasNormal && anyCollision) {
|
||||
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.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_SLIME_BLOCK_FALL,
|
||||
SoundCategory.BLOCKS, .5f, 1);
|
||||
continue;
|
||||
}
|
||||
if (bounce > 0 && hasNormal && anyCollision && bounceEntity(entity, collisionNormal, contraptionEntity, bounce)) {
|
||||
entity.world.playSound(playerType == PlayerType.CLIENT ? (PlayerEntity) entity : null,
|
||||
entity.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_SLIME_BLOCK_FALL,
|
||||
SoundCategory.BLOCKS, .5f, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (temporalCollision) {
|
||||
|
@ -280,7 +276,6 @@ public class ContraptionCollider {
|
|||
}
|
||||
|
||||
if (bounce == 0 && slide > 0 && hasNormal && anyCollision && rotation.hasVerticalRotation()) {
|
||||
collisionNormal = collisionNormal.normalize();
|
||||
Vec3d motionIn = entityMotionNoTemporal.mul(0, 1, 0)
|
||||
.add(0, -.01f, 0);
|
||||
Vec3d slideNormal = collisionNormal.crossProduct(motionIn.crossProduct(collisionNormal))
|
||||
|
@ -338,35 +333,14 @@ public class ContraptionCollider {
|
|||
return false;
|
||||
if (entity.bypassesLandingEffects())
|
||||
return false;
|
||||
if (normal.equals(Vec3d.ZERO))
|
||||
return false;
|
||||
|
||||
Vec3d contraptionVec = Vec3d.ZERO;
|
||||
Vec3d contactPointMotion = contraption.getContactPointMotion(entity.getPositionVec());
|
||||
Vec3d motion = entity.getMotion()
|
||||
.subtract(contactPointMotion);
|
||||
|
||||
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;
|
||||
Vec3d motion = entity.getMotion().subtract(contactPointMotion);
|
||||
Vec3d deltav = normal.scale(factor*2*motion.dotProduct(normal));
|
||||
if (deltav.dotProduct(deltav) < 0.1f)
|
||||
return false;
|
||||
entity.setMotion(entity.getMotion().subtract(deltav));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Vec3d getWorldToLocalTranslation(Entity entity, AbstractContraptionEntity contraptionEntity) {
|
||||
|
|
Loading…
Reference in a new issue