i’m trying to fit my mod(laser turret) with vs mod, here’s a problem which the laser turret cannot aim enemies but always facing one specific direction. I thought it was because vs mod copies all block(entities) to shipyard so the turret got wrong pos from where it was on ship. Anyone has idea to get the correct pos on ship? I’ll be so appreciated!
Reply chain from #27
private static Vec3 getShootLocation(LivingEntity entity, List<Vec3> preV, Level lv,BlockPos pos) {
Vec3 averageVelocity = Vec3.ZERO;
for (Vec3 prevVelo : preV){
averageVelocity = averageVelocity.add(prevVelo);
}
averageVelocity = averageVelocity.scale(1.0 / preV.size());// calculate averageVelocity
Vec3 targetPos = new Vec3(entity.getX(), entity.getY(), entity.getZ());
if(VSGameUtilsKt.getShipObjectManagingPos(lv,pos) != null){
;
}
double laserSpeed = 3F; //Laser speed is constant
for (int i = 1; i < 21; i++) { //Tries to predict the path of the entity one second into the future
Vec3 deltaMovement = averageVelocity.multiply(0.4, 0, 0.4);
Vec3 nextPos = targetPos.add(deltaMovement.scale(i-1));
if(nextPos.length() <= laserSpeed*i || i == 20) {
return new Vec3(nextPos.x, nextPos.y+(entity.getBbHeight()*0.75), nextPos.z-0.07);
}
}
return targetPos;
}
This conversation is on Discord · Reply there