static void DecreaseLifetime(ref ProjectileComponentData projectileData, float deltaTime) { if (projectileData.removeEntityWhenProjectileStops) { projectileData.lifetimeAfterProjectileStop -= deltaTime; } }
static bool MoveProjectile(ref Translation translation, ref ProjectileComponentData projectileData, ref VelocityComponentData velocity, float scale, float deltaTime) { projectileData.itStopsRightNow = false; projectileData.previousProjectilePosition = translation.Value; var acceleration = projectileData.accelerationResistance * -1; var realVelocity = velocity.value * scale; //пока летит - двигаем if (velocity.value.y != 0 || velocity.value.x != 0) { //обновляем велосити velocity.value.x = ANU.Utils.Physics.GetVelocity(velocity.value.x, deltaTime, acceleration.x); velocity.value.y = ANU.Utils.Physics.GetVelocity(velocity.value.y, deltaTime, acceleration.y); //подвинем горизонтально translation.Value.y += ANU.Utils.Physics.GetDisplacement(realVelocity.y, deltaTime, acceleration.y); //если падает вниз и коснулoсь пола, то положим ровно на пол и уменьшим дельта тайм соответствующе пройденому пути if (realVelocity.y < 0)//падает вниз { if ( //если пол - это таргет_У, то останавливаем после достижения У (projectileData.ground == ProjectileComponentData.GrountType.TARGET_Y && translation.Value.y <= projectileData.targetPosition.y) || //если пол - это старт_У, то останавливаем на таргет_У, если упало в радиусе targetWidth от таргет_X. (projectileData.ground == ProjectileComponentData.GrountType.START_Y && translation.Value.y <= projectileData.targetPosition.y && translation.Value.x >= projectileData.targetPosition.x - projectileData.targetWidth / 2 && translation.Value.x <= projectileData.targetPosition.x + projectileData.targetWidth / 2) || //иначе - останавливаем на старт_У (projectileData.ground == ProjectileComponentData.GrountType.START_Y && translation.Value.y <= projectileData.startPosition.y) ) { var delta = ANU.Utils.Physics.GetTime( math.abs(projectileData.targetPosition.y - translation.Value.y), math.abs(realVelocity.y), acceleration.y ); deltaTime -= delta; velocity.value.y = 0; translation.Value.y = projectileData.targetPosition.y; } } //ну и двигаем вбок translation.Value.x += ANU.Utils.Physics.GetDisplacement(realVelocity.x, deltaTime, acceleration.x); if (velocity.value.y == 0) { velocity.value.x = 0; projectileData.itStopsRightNow = true; return(false); } return(true); } return(false); }