mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +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);
|
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,16 +241,11 @@ 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();
|
entity.world.playSound(playerType == PlayerType.CLIENT ? (PlayerEntity) entity : null,
|
||||||
Vec3d newNormal = collisionNormal.crossProduct(collisionNormal.crossProduct(entityMotionNoTemporal))
|
entity.getX(), entity.getY(), entity.getZ(), SoundEvents.BLOCK_SLIME_BLOCK_FALL,
|
||||||
.normalize();
|
SoundCategory.BLOCKS, .5f, 1);
|
||||||
if (bounceEntity(entity, newNormal, contraptionEntity, bounce)) {
|
continue;
|
||||||
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) {
|
if (temporalCollision) {
|
||||||
|
@ -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)
|
return false;
|
||||||
.normalize();
|
entity.setMotion(entity.getMotion().subtract(deltav));
|
||||||
if (v2 != Vec3d.ZERO)
|
return true;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec3d getWorldToLocalTranslation(Entity entity, AbstractContraptionEntity contraptionEntity) {
|
public static Vec3d getWorldToLocalTranslation(Entity entity, AbstractContraptionEntity contraptionEntity) {
|
||||||
|
|
Loading…
Reference in a new issue